Hello,

The content of DATA are modified  %hash value. Need to include  %hash key before or after  SOME_DATA to respective modified  %hash key

Don't know how to search modified  value and include respective  key after or before  SOME_DATA

__HASH__ $VAR1 = { 'Key1' => 'Cat.Mouse.Game.Lion.Tiger.Elephant', 'Key2' => 'Cat.Mouse.Game.Lion.Tiger.Lion', 'Key3' => 'Cat.Mouse.Game.Lion.Tiger.Monkey', };
__DATA__ Pigeon.Lion.Tiger.Elephant SOME_DATA Pigeon.Lion.Tiger.Lion SOME_DATA Pigeon.Lion.Tiger.Monkey SOME_DATA
__Example code__ my %hash = () my $file = 'master.txt'; open (my $OUT_FILE, '<', "TEXT_FILE") or die "ERROR"; while (<$OUT_FILE>) { print "$. \n" if /SOME_DATA/; #searching SOME_DATA and printing }
__OUTPUT__ Pigeon.Lion.Tiger.Elephant SOME_DATA (Key1) Pigeon.Lion.Tiger.Monkey SOME_DATA (Key3)

UPDATED:

%hash value "Cat.Mouse.Game" is replaced with "Pigeon" and placed in a text file along with SOME_DATA

Ignore "Pigeon" and match other characters. If there is a match, then include respective %hash Key before "SOME_DATA"


In reply to Array and Hash 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.