iphone has asked for the wisdom of the Perl Monks concerning the following question:

The below code scans through a directory to gets all the ".plf" files and then stores the filenames as key and the lines in the files as values.My problem I see duplicate values for the filenames(keys) and values(lines in the files).Not sure what's going wrong?can anyone help?

my $start_dir; my $file_name = "mjnload.cmm"; opendir(DIR, "$start_dir"); @plf_files = grep(/\.plf$/,readdir(DIR)); print "PLF FILES\n"; print "@plf_files\n";--->there are no duplicates closedir(DIR); foreach my $plf (@plf_files) { chomp($plf); open my $match, '<',"$start_dir\\$plf" or die "could not open '$plf' $ +!"; my @file_lines = <$match>; $Hash_filenames{$plf}=\@file_lines; } open my $hash, '>>', "hash.txt"; print $hash Dumper( \%Hash_filenames );

Replies are listed 'Best First'.
Re: why is my hash having duplicate keys and values?
by iphone (Beadle) on Nov 02, 2010 at 04:41 UTC
    Ignore this query..I am appending data to the file,that's why its showing multiple times
      Glad you figured it out, and thanks for posting the solution/cause!