waytoperl has asked for the wisdom of the Perl Monks concerning the following question:
How to compare hash value exists in text file. If exists then print key & value exists. Hash table have identical values stored in hash Keys.
Text file contents:
line 1 have some string here and Hash_key_4: Hash_value_4_identical_to +_Hash_value_9 line 2 have some string here and Hash_key_5: Hash_value_5 line 3 have some string here and Hash_key_6: Hash_value_6 line 4 have some string here and Hash_key_7: Hash_value_7_identical_to +_Hash_value_2 line 5 have some string here and Hash_key_1: Hash_value_1 line 6 have some string here and Hash_key_2: Hash_value_2_identical_to +_Hash_value_7 line 7 have some string here and Hash_key_3: Hash_value_3 line 8 have some string here and Hash_key_8: Hash_value_8 line 9 have some string here and Hash_key_9: Hash_value_9_identical_to +_Hash_value_4 line 10 have some string here and Hash_key_10: Hash_value_10 .... ....
Hash table: Key are not identical. Few Values are identical.
Hash_key_1 => Hash_value_1 Hash_key_2 => Hash_value_2_identical_to_Hash_value_7 Hash_key_3 => Hash_value_3 Hash_key_4 => Hash_value_4_is_identical_to_Hash_value_9 Hash_key_5 => Hash_value_5 Hash_key_6 => Hash_value_6 Hash_key_7 => Hash_value_7_identical_to_Hash_value_2 Hash_key_8 => Hash_value_8 Hash_key_9 => Hash_value_9_is_identical_to_Hash_value_4 Hash_key_10 => Hash_value_10 .... ....
Please help
my %hash = (); my $filename = "input_text.txt"; open FILE,"<$filename" or die "Cannot read the file $filename: $!\n"; foreach <FILE> { if (my $line =~ m/{$Hash_value{key}}/) { print "$line has $hash{$key} and value is $hash{key}\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: compare text file and print occurrence of key and value
by Laurent_R (Canon) on Sep 23, 2014 at 21:02 UTC | |
by waytoperl (Beadle) on Sep 28, 2014 at 14:22 UTC | |
by Laurent_R (Canon) on Sep 28, 2014 at 17:36 UTC | |
|
Re: compare text file and print occurrence of key and value
by Laurent_R (Canon) on Sep 23, 2014 at 20:44 UTC | |
|
Re: compare text file and print occurrence of key and value
by AppleFritter (Vicar) on Sep 23, 2014 at 20:31 UTC |