Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by ejbiers (Initiate)
on Aug 07, 2012 at 13:45 UTC ( #985988=note: print w/ replies, xml ) Need Help??


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

This is perfect! Thanks! However, is there a way to print the results into an output file?


Comment on Re^2: compare two files by column and return second (matching) column
Re^3: compare two files by column and return second (matching) column
by Kenosis (Priest) on Aug 07, 2012 at 15:28 UTC

    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;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985988]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-08-21 08:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (128 votes), past polls