in reply to Compare 2 files and create a new one if it matches

Here is what I would do (code snippets untested):

This may not be the fastest approach, but it does only open and read each of your input files once. As opposed to 60,000 X 16,000,000 = 960,000,000,000 times - which is what your current code does.
So I'd expect it to be just a tad faster ;)

Hope this helps,
Darren :)

Replies are listed 'Best First'.
Re^2: Compare 2 files and create a new one if it matches
by GrandFather (Saint) on Sep 20, 2008 at 03:39 UTC

    Actually your code is only about 60,000 times faster than the OP's code. The large file is opened and read once for each line (60,000 times that is) in the smaller file in the OP's version. The smaller file is opened and read once only.

    In other respects your reply is pretty much the same as ikegami and my replies ;).


    Perl reduces RSI - it saves typing