Excellent suggestions have been given. Here's another option:
use Modern::Perl; open my $fhA, '<', 'FileA.txt' or die $!; my %hash = map { /(.+)\t(.+)/; $1 => $2 } grep /\S/, <$fhA>; close $fhA; open my $fhB, '<', 'FileB.txt' or die $!; say for map { chomp; $hash{$_} } grep /\S/, <$fhB>; close $fhB;
Output:
zzzzz bbbbb xxxxx
The first map uses a regex to grab the key/value pairs from FileA for placement into %hash. The second map uses the single entry from FileB to show that entry's associated value from FileA. Since there were blank lines in the files (from your data set), grep /\S/ was used to filter those.
Hope this helps!
In reply to Re: compare two files by column and return second (matching) column
by Kenosis
in thread compare two files by column and return second (matching) column
by ejbiers
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |