Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: 2 files

by Laurent_R (Canon)
on Dec 05, 2018 at 23:50 UTC ( [id://1226810]=note: print w/replies, xml ) Need Help??


in reply to 2 files

Hi Deicide,

it would be most useful to see your code, as well as some samples of your input and desired output.

As a general rule, when you're looking for records (or parts of records) that are in file 2 and not in file 1, the best method is to read file 1 and to store the data of interest of file 1 in a hash; and then to scan file 2 and keep the records not matching the hash. BTW, a hash will remove the duplicates.

Not knowing anything about your input files (e.g., what is the record separator?), I can't suggest any real code. But the basic idea in pseudo-code is:

Open file 1 and read file 1 record by record, and: for (each record) { get column D from the record; get the interesting part from column D; store the interesting part in a hash: some thing like: $hash{inter +esting part} = 1; } close file 1 open file 2 and read file 2 record by record, and: for (each record) { get column D from the record; get the interesting part from column D; if (exists $hash{interesting part}) { print $hash{interesting part}; } } close file 2;

I (and other monks here) will be able to provide actual code if you provide the necessary information (especially sample input and desires output).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found