waytoperl has asked for the wisdom of the Perl Monks concerning the following question:
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"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array and Hash
by GrandFather (Saint) on Nov 23, 2014 at 22:39 UTC | |
|
Re: Array and Hash
by 2teez (Vicar) on Nov 24, 2014 at 02:51 UTC | |
|
Re: Array and Hash
by Loops (Curate) on Nov 23, 2014 at 22:49 UTC | |
|
Re: Array and Hash
by wjw (Priest) on Nov 23, 2014 at 23:22 UTC |