I have a huge log file (millions of lines/records) that is parsed line by line in a script. The user can input a file containing lines that if the record contains any of those lines I skip that line.
The option to input this file creates a bottleneck in my script. It takes more that 10 times as much to execute when that option is given.
This is the code that I currently have:
# $line is the current line
# @bypList is the array containing all lines in the skip file
sub check_bypass
{
my $line= shift;
my @bypList= @_;
my $ret= 1;
foreach(@bypList) {
if($line=~/$_/i)
{ $ret= 0; }
}
return $ret;
}
As you can see the solution that have goes through each element of the array for every line. I though about using a hash but it didn't work because it isn't an exact match so I have to run a regExp to see if the line contains any of the lines of the skip arr.
How can I improve on this. Thanks!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.