Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!psuvax1!wuarchive!usc!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: Help : Array of FILEHANDLEs Message-ID: <1991Jan24.214653.25808@iwarp.intel.com> Date: 24 Jan 91 21:46:53 GMT References: Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Distribution: usa Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 36 In-Reply-To: ca@saryu.usa (Cengiz Alaetinoglu) In article , ca@saryu (Cengiz Alaetinoglu) writes: | | I am new to perl. I am trying to open arbitrary no of files, and write to each | of them. What I wanna do is like | | #!/usr/local/bin/perl | | for ($i=0; $i < 5; $i++) { | open($files[$i], "| foo"); | printf $files[$i] "Hello world \n"; | } Hmm. We were just discussing this. You need either a filehandle or a simple scalar after the print/printf. And, you also need a named filehandle for each name. for ($i=0; $i < 5; $i++) { $handle = "FILE$i"; open($handle, "| foo"); printf $handle "Hello world \n"; } This makes 6 filehandles named FILE0 through FILE6. You can use those directly later, as in: print FILE4 "some more for four\n"; And, unless you are doing "%"-style escapes, you probably want just a print, not a printf. eval q#die "Just another Perl hacker,\n"#; print $@ -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/