in reply to Looping through a file to find a hash key
Here's a very simple example showing how to use grep to do what you want (although that may not be the best way!):
Output:use strict; use warnings; use feature qw/ say /; my %hash_name = ( "one" => 1, "two" => 2, "three" => 3, "four" => 4 ); while ( my $line = <DATA> ) { chomp $line; say "Line $. : $hash_name{$_}" for grep { $line =~ /$_/ } sort key +s %hash_name; } __DATA__ This one has it. This doesn't. This one has two. Nothing here. Three times lucky. Can we get a foursome for tennis? Blerghh.
Line 1 : 1 Line 3 : 1 Line 3 : 2 Line 6 : 4
Hope this helps!
|
|---|