Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: How can I create an array of filehandles?

by chromatic (Archbishop)
on Apr 25, 2000 at 18:26 UTC ( [id://8968]=note: print w/replies, xml ) Need Help??


in reply to How can I create an array of filehandles?

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://8968]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-03-29 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found