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"; } }

In reply to compare text file and print occurrence of key and value by waytoperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.