Did you tested it against Benchmark? There are some perl monks that believe that qr works better then using /o in regex matching (but I never tried to compare both). Anyway, if you use one of them you might get better results since the regex will not be compiled again and again.

Updated: sorry, /o will do absolute nothing as described below:

It should be immediately apparent that using /o on a regex with *no* interpolation has zero effect. You could use it on a regex that uses interpolation but then you get delayed runtime effects. In general I'd much prefer all of my compilation to occur at compilation time. As a matter of practice string evals are restricted, this works similarly. If you use qr// expressions then you've shunted the regex compilation and syntax checking off to the normal script compilation time. The alternative is that you discover a syntax error at runtime. Yuck.

More information about that is here: /o is dead, long live qr//!. By the other hand, qr should work.

Other suggestion is that you try to play around with unpack and see if you cannot parse the line without regular expression.

The other things I see you could try is to load the entire file into memory and use foreach instead using while (of course, this will depend of the file size and available memory that you have). Also you may try to instead of print $file, $user, $level put this information into an array to print at the end of the script, to avoid system calls.

And as last resources (since these may give you a lot of work but bringing little results), you may want to remove use strict and -w, as you're not gonna need them if you consider that the code is stable enough. perlcc -B may also help, specially because your program is not importing any module.

One thing that I didn't understand in your code is why it doesn't close the filehandles. The block labels were also not necessary there and the last print statement could be used outside the loop.

Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

In reply to Re^3: Optimising a search of several thousand files by glasswalk3r
in thread Optimising a search of several thousand files by McDarren

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.