But I gather that you don't really need to do that. If all you need is to read in file in turn, it's better to just have one open at a time. BTW, your comment about the strangeness of reading files line by line leads me to think you might like the following approach better:my %fh; for my $i ( 2, 3 ) { my $fname = sprintf( "T%dT.txt", $i ); open( $fh{$fname}, "<", $fname ) or die "$fname: $!\n"; } # you now have multiple file handles indexed by file name in %fh
my %filedata; for my $i ( 2 .. 3 ) { my $fname = sprintf( "T%dT.txt", $i ); open( I, $fname ) or die "$fname: $!\n"; local $/; # temporarily sets input record separator to "undef" $filedata{$fname} = <I>; close I; } # you now have the full content of each file as a single string value, # indexed by file name in %filedata
In reply to Re: Using a loop to process multiple files
by graff
in thread Using a loop to process multiple files
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |