Actually it goes quite fast.

I first made your two 1.5 million row files to test. The ID has a lenght of 38 characters and is guaranteed to be unique within each file. Some IDs however can be found in both files.

The following program reads both files and produces three arrays: @both (containing the IDs which were found in both files), @first and @second (IDs only found in one of both files).

use Modern::Perl; my %first_file; { open my $FIRST, '<', 'first.txt' or die $!; while (<$FIRST>) { chomp; $first_file{$_} = '' ; } } my (@both, @first, @second); { open my $SECOND, '<', 'second.txt' or die $!; while (<$SECOND>) { chomp; if (exists $first_file{$_}) { push @both, $_; delete $first_file{$_}; } else { push @second, $_; } } } @first = keys %first_file;
On my Windows XP Lenovo X200s laptop running Perl 5.12 it takes 5 seconds to read the first file into the hash and 10 seconds to check the second file against the hash and putting the IDs in their respective arrays.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James


In reply to Re: Help for finding duplicates in huge files by CountZero
in thread Help for finding duplicates in huge files by julio_514

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.