I'm working on a module that parses logs. I've got about 20 different line types. The idea is to stuff a hash with the regex ( qq{} ), the general name of the line, and some other trivial things.

Here is what I have right now:

elsif (/..a regex goes here../) { if(ref($self->{_ref_killed}) eq 'CODE'){ $self->{_ref_killed}->($1,$2,$3) } elsif(ref($self->{_ref_killed}) eq 'ARRAY'){ foreach my $sr (@{$self->{_ref_killed}}){$sr->($1,$2,$3)} } elsif(ref($self->{_ref_default}) eq 'CODE'){ $self->{_ref_default}->($1,$2,$3) } $self->_last_death($2); }
"killed" would be that code chunks "name" (from reference above.)

As with all log parsing, I'm racing for time. Some benchmarks showed a simple ++ operation with and without eval:

Without Eval: 0.059999942779541 With Eval: 4.15600001811981

So eval is out of the question. As I said above, I'd personally perfer to have a hash of arrays:

$type{killed} = [$regexref,3]; # 3 to pass $1,$2, and $3 #above is not exact and has problems I'm sure. Just for the idea.
If I can make this all a big maintainable hash, that would be far superior to having the same (generally) code repeated over and over.

Any ideas? Thanks,


In reply to Speed vs Laziness 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.