> Is there a simple way to generate unique handles automatically for each element in my array of input files, without typing out a silly array like the @FileHandles shown above?

I'd rather use a hash to hold the %handle per path.

DB<111> $path='/tmp/path' => "/tmp/path" DB<112> open $handle{$path},">",$path; => 1 DB<113> $handle{$path}->print("This is File $path") => 1 DB<114> close $handle{$path} => 1 DB<115> `cat $path` => "This is File /tmp/path"

This works for me, but plz note that I had to use the normal (and saner) method call syntax for print.

But I have to doubt that you really need to open 100 files simultaneously, maybe you should consider a better algorithm which works sequentially?

HTH! =)

Cheers Rolf

( addicted to the Perl Programming Language)

edit

another limitation is that you can't use < ... > syntax for readline

DB<127> open $handle{$path},"<",$path; => 1 DB<128> ref $handle{$path} => "GLOB" DB<129> print while (<$handle{$path}>) GLOB(0x8f19688) DB<130> print while (readline($handle{$path})) This is File /tmp/path DB<131> seek $handle{$path},0,0 => 1 DB<132> readline($handle{$path}) => "This is File /tmp/path"

update

anyway looping over the hash fixes all syntactic "anomalies" again

DB<151> while ( my ($path,$handle) = each %handle ) { print <$handle>; } This is File /tmp/path

update

Just to be sure, no trouble with strict!

DB<159> ;{ use strict; my $path="/tmp/path"; my %handle; open $handle{$path},"<",$path; while ( my ($path,$handle) = each %handle ) { print <$handle>; } } This is File /tmp/path

In reply to Re: File handles - there must be a better way (hash) by LanX
in thread File handles - there must be a better way 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.