Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: File handles in regular expressions

by Laurent_R (Vicar)
on Oct 21, 2012 at 13:02 UTC ( #1000218=note: print w/ replies, xml ) Need Help??


in reply to File handles in regular expressions

First, three comments:

1. check the status of the open instructions;

2. chomp the lines you are reading to remove newline characters

3. use the eq operator instead of a regex, unless you have good reason to use regexes.

If the files are not too large (or, rather, if at least one of the files is not too large), read one of the files and store it in memory as a hash (using the full chomped line as the key). Once this is done, go through the other file and check if the line exists in the hash. If it exists, juste print it to your output file. This will be much faster than your nested foreach loops.


Comment on Re: File handles in regular expressions

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-08-23 17:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (175 votes), past polls