Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Merging Files: A Different Twist

by chromatic (Archbishop)
on Sep 15, 2000 at 06:08 UTC ( [id://32605]=note: print w/replies, xml ) Need Help??


in reply to Merging Files: A Different Twist

This sounds like a case for a full fledged database... something like DBD::RAM could come in very handy.

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:

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
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.

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found