Hi,

I posted this question on Perl Guru, and someone suggested I might want to try here instead for a potentially better response.

I have written some perl code dealing with large amounts of data. The script reads in one line at a time from a flat file, then searches the line for any reference to information from another flat file. This creates a nested loop, and when one flat file is 300mb+ and the other is 1mb, it takes a while to run. Any suggestions for improving the performance of this code?

Thanks!

The offending code:
#%hash has been filled with some meta data in an array read in #from the smaller flat file #The first element is the name we are searching for. #the rest are irrelevant to this loop # #fh_log is a file handle to the large 300mb+ flat file #each line may contain references to 1 or more table names, and #I need to capture all of them. while($cur_line=<fh_log>) { foreach $key (keys %hash) { $table = $hash{$key}[0]; #If this query contains reference to this table if($cur_line=~ m/$table/i) { #count up how many times this table is referenced. $table_stats{$table}++; $table_refs++; #total table references (for % calc) } } }

In reply to Perl Optimization by Chivalri

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.