in reply to building a hash with filname and itscontents
I think you also need to include the path with the file name when doing the "-d" test, unless that path happens to be the current working directory when you run the script. (I'm assuming the directory you're reading could contain subdirectories.)
Apart from that, why do you cast the hash into an anonymous array when passing it to Data::Dumper? (Just curious -- normally, I'd expect something like print Dumper( \%hash ); .)
Did you consider slurping the file, to simplify the structure? (You can always do "split /\n/" as needed later on.)
And don't you hate having to put in long string literals more than once? I do -- so much so that it's worth declaring another scalar:
my %spr_hash; # you do use strict, don't you? my $path = "/apps/inst1/metrica/TechnologyPacks/ON-SITE/Nokia_S11.5/re +portspr"; opendir( D, $path ) or die "$path: $!"; while ( my $file = readdir( D )) { next if ( -d "$path/$file" ); open( F, "<", "$path/$file" ) or die "$path/$file: $!"; # @{$spr_hash{$file}} = <F>; # I'd rather slurp to a scalar: { local $/; $spr_hash{file} = <F>; } } print Dumper( \%spr_hash );
|
|---|