note
2teez
<p>
Hi [waytoperl],<br><br>
Considering, the __DATA__ and the hash data presented, there is no way you are getting this desired output
<c>
Pigeon.Lion.Tiger.Elephant SOME_DATA (Key1)
Pigeon.Lion.Tiger.Monkey SOME_DATA (Key3)
</c>
Why? <br>
<ul>
<li>If "Pigeon." and " SOME_DATA" is taken away from your input coming from __DATA__, compare with your hash data if "Cat.Mouse.Game." is taken away you practically have these:
<ol>
<li>Lion.Tiger.Elephant</li>
<li>Lion.Tiger.Lion</li>
<li>Lion.Tiger.Monkey</li>
</ol></li>
<li>
With " SOME_DATA" common to all input, one cannot use it to differentiate, when comparing with the hash data given.
</li>
<li>And with the OP update given, all compared data will match, <b>except</b> if there is some kind of changed in input data. Then would the (key2) not match</li>
</ul>
Something like this:
<c>
use warnings;
use strict;
my %hash = (
'Key1' => 'Cat.Mouse.Game.Lion.Tiger.Elephant',
'Key2' => 'Cat.Mouse.Game.Lion.Tiger.Lion',
'Key3' => 'Cat.Mouse.Game.Lion.Tiger.Monkey',
);
while ( my $data = <DATA> ) {
chomp($data);
my $value = join '.' => ( split /[\s.]/, $data )[ 1 .. 3 ];
print map { "$data ($_)\n" if $hash{$_} =~ /$value/ } keys %hash;
}
__DATA__
Pigeon.Lion.Tiger.Elephant SOME_DATA
Pigeon.Lion.Tiger.SeaLion SOME_DATA
Pigeon.Lion.Tiger.Monkey SOME_DATA
</c>
OUTPUT
<c>
Pigeon.Lion.Tiger.Elephant SOME_DATA (Key1)
Pigeon.Lion.Tiger.Monkey SOME_DATA (Key3)
</c>
Please note that the input data has been changed from what the OP gave.
<br><br>
With the OP input, the output will be:
<c>
Pigeon.Lion.Tiger.Elephant SOME_DATA (Key1)
Pigeon.Lion.Tiger.Lion SOME_DATA (Key2)
Pigeon.Lion.Tiger.Monkey SOME_DATA (Key3)
</c>
</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-918402">
If you tell me, I'll forget.<br>
If you show me, I'll remember.<br>
if you involve me, I'll understand.<br>
--- Author [unknown to me]
</div></div>
1108186
1108186