Yes, it should be slow; you're reading 180 MB files 3000 or so times. Is there some ordering relationship that you can exploit so that you only have to read the 180MB files once? I can guess that the files would be ordered by date+time. If that's the case, you could do something like this (obviously untested):

#!/usr/bin/perl use warnings; use strict; $[ = 1; $\ = "\n"; my ($last_xdrfile,$xline); open CDR_DETAILS, "cdr_details.1" or die "couldn't open cdr_details.1: + $!\n"; open CDR_TDM, ">cdr_tdm.csv" or die "couldn't write cdr_tdm.csv: $!\n" +; while (<CDR_DETAILS>) { chomp; my ($cdrdate,$cdrtime,$cdrcli1,$cdrcli2,$xdrfile) = (split /,/)[1, +2,3,7,8]; $cdrtime += 0; print "Record number: $."; print "CDRDATE: $cdrdate"; print "CDRTIME: $cdrtime"; print "CLI1: $cdrcli1"; print "CLI2: $cdrcli2"; if ($last_xdrfile ne $xdrfile) { print "$xdrfile != $last_xdrfile, opening file!"; open(XDR,$xdrfile) or die "couldn't open $xdrfile: $!\n"; chomp($xline = <XDR>); } $last_xdrfile = $xdrfile; while (defined $xline) { my ($xdrdate,$xdrtime,$xdrcli1,$xdrcli2)=(split /,/, $xline)[2 +,3,5,7]; last if $xdrdate gt $cdrdate; last if $xdrtime gt $cdrtime; next unless $xdrdate eq $cdrdate && $xdrtime eq $cdrtime && $xdrcli1 eq $cdrcli1 && $xdrcli1 eq $cdrcli2; print CDR_TDM $xline; } continue { chomp($xline = <XDR>) } }
I'm making some gross assumptions about the formats of the date and time though. If they're not in a format that's directly comparable, you'll need to convert to a form that is (possibly using something like Date::Parse)

What my version does is rather than read the entire 180MB file into memory, it reads it a line at a time assuming both this file and the one generating the "searches" are in date+time order. There are a couple of gyrations to get the XDRFILE to read properly:


In reply to Re: Should this be so slow ? by duff
in thread Should this be so slow ? by phi.jones

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.