Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: File handles in regular expressions

by Laurent_R (Canon)
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000218]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2018-06-22 00:17 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (120 votes). Check out past polls.