in reply to Re^2: search log file with multiple word and count number of success
in thread search log file with multiple word and count number of success
my ($current_date) = map { qr/$_/ } (scalar localtime) =~ /\w+ +(\w+ + +\d+)/;
and put them in a meaningful variable.my @errors = map {qr/$_/} qw( error4 error3 error2 error1 );
open my $LOGFILE, '<', $log_file or die "can not open $log_file for writing: $!\n";
with$w = 1; while ($w <= @word_search) { # uses $w - 1 to get $word_search[$w - 1] $w++; }
or better still don't split the line and do away with the loop altogether.foreach my $w ( 0 .. $#word_search ) { # uses $w to get $word_search[$w] }
This is where your logic utterly fails. You test the same word for equality with two different words, $pattern_date and "error4". Not only that but the date from the log file is in two separate words since split them apart to get your list of words.
Note you don't initialise $count or ever change its value, you are always testing against the same error.if ($word_search[$w-1] eq $pattern_date && $word_search[$w-1] eq $arra +y[$count])
if ( $line =~ /$current_date/ ) { foreach my $error (@errors) { # count all the errors on the line ++$error_count while ($line =~ /($error)/g); } }
I leave final assembly to the reader ;-).
Just noticed I had clicked on create rather than preview while composing this. Hope I didn't cause too much distress to our regular viewers.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: search log file with multiple word and count number of success
by steadybompipi (Novice) on Feb 24, 2008 at 13:59 UTC |