in reply to Re^2: Dynamic File Handles
in thread Dynamic File Handles
Here's a subroutine that will return a hashref, where the keys are the filenames passed in (for those that it is able to open), and the values are filehandles.
updated: removed extraneous "my $fh"
sub open_files { my @files = @_; my %file_handles; for my $file ( @files ) { if ( open my $fh, '<', $file ) { $file_handles{ $file } = $fh; } else { warn "couldn't open $file for reading: $!\n"; } return \%file_handles; }
-Colin.
|
---|