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

I have some general advice for you, but I'll wait till I'm sober. Till then:

use strict; use warnings; my %data; open (DATA1, "<", "data1.txt") or die "cannot open file"; while (<DATA1>) { my @line = split (/\t/, $_); $data{$line[0]} = $line[1]; } my @k = keys %data; foreach my $key (@k) { print "$key, $data{$key}\n"; } close DATA1; open (DATA2, "<", "data2.txt") or die "cannot open file"; print "found:\n"; while (<DATA2>) { chomp; if (exists $data{"$_"}) {print "$data{$_}\n";} close DATA2;
This doesn't check duplicates, is too verbose, but I hope it'll help.

I'm too lazy to be proud of being impatient.
  • Comment on Re: compare two files by column and return second (matching) column
  • Download Code