hi there, i am a new perl person, but did a lot of php.

i am writing a web log parsing thingie. it is looking for a couple of regexes and counts some stuff, really simple. on a 200M logfile, it takes around 8.35s real 8.20s user 0.14s system with ONE $mask. as soon as i put 2 or more, the time goes over 100s... i tried to profile, but -d:DProf does not profile builtins.

the script is "learning" the filenames in a particlar path, and pushing them on the array. so before the pushing it checks if there is already a file with the same name.

$ cat test.pl use strict; use File::Basename; my @count = (); my @mask = ( '/some/path/', 'some/other/path', 'another/path', ); open F, "access.log"; while (<F>) { chomp; foreach my $m (@mask) { my $regex = "GET.*" . $m . ".*HTTP/1.1\" 200 [0-9].*"; if (/$regex/) { s/.*GET //; s/ HTTP.*//; my $bn = basename($_); my $found = 0; foreach (@count) { if ($_->[0] eq $bn) { $_->[1]++; $found = 1; last; } } if ($found == 0) { push @count, [ $bn, 1 ]; } } } } foreach (@count) { print "$_->[0] = $_->[1]\n"; } close F;
(all this on red hat ES3)

In reply to log parsing very slow by Anonymous Monk

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.