Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Answer: How can I create an array of filehandles?

by chromatic (Archbishop)
on Apr 25, 2000 at 18:26 UTC ( #8968=categorized answer: print w/replies, xml ) Need Help??

Q&A > files > How can I create an array of filehandles? - Answer contributed by chromatic

With the Symbol module, you can use gensym() to create a new, anonymous typeglob. Since that's the customary way to get at a filehandle, you can do something like this, to create an array of anonymous filehandles:
#!/usr/bin/perl -w use strict; use Symbol; my @handles; for (1 .. 2) { my $fh = gensym; open $fh, "test$_"; push @handles, $fh; } foreach my $handle (@handles) { print while (<$handle>); print "---\n"; close $handle; }
In a production environment, I wouldn't use a symbolic reference to a filename like I do in the first loop, but this is just an example.

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2016-12-09 06:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (148 votes). Check out past polls.