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)
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"
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
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |