in reply to Dynamic File Handles
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.
|
|---|