Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: compare two files by column and return second (matching) column

by Kenosis (Priest)
on Aug 07, 2012 at 15:28 UTC ( #986018=note: print w/replies, xml ) Need Help??


in reply to Re^2: compare two files by column and return second (matching) column
in thread compare two files by column and return second (matching) column

You're most welcome, ejbiers! Yes, the script below includes printing the results to a file:

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 $!; my @output = map { chomp; $hash{$_} } grep /\S/, <$fhB>; close $fhB; open my $fhO, '>', 'Output.txt' or die $!; say $fhO $_ for @output; close $fhO;
  • Comment on Re^3: compare two files by column and return second (matching) column
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986018]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2016-12-04 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (64 votes). Check out past polls.