in reply to Multiple patterns match in a big file and track the counts of each pattern matched
# initialize the array of patterns # the same code as you use in your script, just complete the line my @pat_array = ...; # this is new hash variable used for counting matches # it used entirely instead your approach my %match_count; # skip first lines # simple read them and do nothing over them <LOG_READ> for ( 1..$InStartLineNumber ); # normal work # read line by line the rest of the file and do something while ( <LOG_READ> ) { # read the line, and store in the variable explicitly chomp; my $line = $_; # walk through the list of patterns # test the line for matching each pattern # and count every successful match in the hash map { $line =~ m/\Q$_\E/ and $match_count{$_}++; } @pat_array; } # The rest of code handling with @pat_array and %match_count
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Multiple patterns match in a big file and track the counts of each pattern matched
by ansh007 (Novice) on Dec 04, 2017 at 11:11 UTC | |
by siberia-man (Friar) on Dec 04, 2017 at 19:59 UTC |