Quoting "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>:

>I'm doing some optimizing on a script (using timethese 
> and cmpthese calls in stub programs) and I was wondering about this. I 
> know the compile-once option on regular expressions has been maligned, but 
> I've found that it gets me about a 3% increase on one piece of code that
> uses a for loop with regexps as a pseudo-switch statement (just like in
> the Camel book).

Can I ask a question?, Would it be faster to eliminate all of the regex 
matches and forget about the half poofteenth per transaction saving from /o 
and use the incoming value of $line as an index to a hash of accepted values?

something like this:

#pre-declare a hash of your actions outside where you declare %hashA, %hashB 
etc. You could possibly use refs to anonymous subs as hash values to do more 
complex things and tidy up duplication...


%actions = (    0 => $val,
                1 => $hashC{$val},
                 ...
                51 => $hashA{$val}
        );
                                
sub Translate{
        my ($row,$val) = @_;
        my $out = $actions{$row} || 'N/A';
        return( $row, $out ); 
}


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to