in reply to Merging Files: A Different Twist
If I understand your specification, however, you want to get data from one column in the first file, look for matches in one column of the second file and print the whole row that contains a match.
This is why hashes were invented:
That's very generic, and you'll probably want to change the split regex, at least. $column1 and $column2 are the 0-based numeric values of the columns you want to grab out of the specific files.my %to_match = (); # hold things to match in here my $output = ''; # hold what we want to print # open first file while (<FILE1>) { my $element = (split(/\t/, $_))[$column1]; $to_match{$element} = 1; } # open second file while (<FILE2>) { my $element = (split(/\t/, $_))[$column2]; if (defined($to_match{$element})) { $output .= $_; } } # open output file and display results
If you don't have *exact* matches, you'll have to use a regex or String::Approx or something to do a fuzzy match. This ought to get you started, though.
|
---|