in reply to File handles - there must be a better way

> 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