Not sure exactly what you are trying to achieve. However, it is easy to open multiple file handles at the same time. For example, you could use an array of file names and a "parallel" array of file handles, as shown in the example code below:

use strict; use warnings; my @files = qw(file1 file2 file3); my @fh; foreach my $i (0..$#files) { open($fh[$i], $files[$i]) or die "open '$files[$i]': $!"; } foreach my $fh (@fh) { while(<$fh>) { print; } } foreach my $i (0..$#files) { close($fh[$i]) or die "close '$files[$i]': $!"; }

Update: from perldoc -f open, "If FILEHANDLE is an undefined scalar variable (or array or hash element) the variable is assigned a reference to a new anonymous filehandle". In the open call in the example code above, I am using an undefined array element ($fh[$i]) to receive the new anonymous filehandle.


In reply to Re: Dynamic File Handles by eyepopslikeamosquito
in thread Dynamic File Handles by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.