good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: How can I create an array of filehandles?by CharlesClarkson (Curate) |
on Jun 11, 2001 at 09:35 UTC ( [id://87404]=note: print w/replies, xml ) | Need Help?? |
As of Perl 5.6.0 file handles can be autovivified. So it is possible to open a file like this:
This allows us to refer to the filehandle as $fh. The following sub returns a hash keyed to the file names:
Note that files that cannot be opened are not defined in the hash. Now the files can be referred to from %handles:
or:
To return an array we need to decide what happens if a file can't be opened. This sub dies:
While this will return undef for failed opens:
In Section
Seekers of Perl Wisdom
|
|