Hi, I am pasting a snippet of my code. The below code get multiple files ($file_name) and then grep for each file_name in the values of a hash(Hash_filenames) and then save the grep that matches in another hash(Hash_filematches).The issue is only the data of the last file_name is getting saved.How do I fix it?
while (my $line = <$DATA>){ (my $file_name) = $line =~ / ........... if ( ($file_name) and ( !$seen_file{$file_name}++ ) ) { foreach my $filename(keys %Hash_filenames) { @{ $Hash_filematches{ $filename } } = grep( /\/\Q$file_name\E#/i +, @{ $Hash_filenames{ $filename } });--------->@{ $Hash_filematches{ +$filename } } stores only the grep of the last $file_name }#for loop end }#if file_name end .... for my $key (keys %Hash_filematches) { my $value = $Hash_filematches{$key}; if (scalar @$value) { # check that the arrayref isn't empty print "KEY: $key\n"; print "VALUES: ", join(", ", @$value), "\n\n"; } }
In reply to Only the last file data is getting saved in the hash by iphone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |