in reply to Re: grepping for
in thread grepping for

Instead of your current while loop try this one which should be somewhat faster. I replaced your first regular expressions with a "substr eq" combination.
my $dir='/acm/'; my $strlen=length ($dir) while (<LOG>) { my $url = (split())[6]; if ((substr($url,0,$strlen) eq $dir) && ($url=~/$error/)) { if (exists $report{$url}) { $report{$url}++; } else { $report{$url} = 1; } } }
I benchmarked this using some sample data I made up and it is about %35 faster than the original version. Your performance may vary.

Regular-expressions are slower than straight string operations. So if you can accomplish what you want with string operations and performance matters, then you can tune your code by replacing some regular-expressions with string operations (only feasible for simple regular-expressions).

Replies are listed 'Best First'.
RE: RE: Re: grepping for
by jjhorner (Hermit) on May 12, 2000 at 21:38 UTC
    Your code looks good, but in order for me to get the right error codes, $url needs to be checked either against the entire line, or against $_[-1]. Thanks again, JJ