Any number of lines here possibly including another begin.0000HA-00001 begin
Any number of lines here possibly including another begin.0000HA-00001 doing-work
File continues.0000HA-00002 complete
For each line containing serial number and begin I have to find the matching, doing-work and complete entries. If the matching entries do not exist report it.
My code (untested)
#!/usr/bin/perl use strict; use warnings; my (@entries, $x, $doing, $complete); open FH, "logfile"; while <FH>{ if (m/(\w{6}-\w{5})\s+begin/){ push @entries, $1; } } close FH; foreach $x (@entries){ open FH, "logfile"; while <FH>{ if (m/$x\s+doing-work/){ $doing = 1; } if (m/$x\s+complete/){ $complete = 1; } } close FH; if ($doing == 1 && $complete == 1){ $doing = 0; $complete = 0; next; #failed ! }else{ push @failed, $x; } } print "These entries have failed\n"; foreach $x (@entries){ print $x."\n"; }
This invovles going through the log file many times. Is there a more efficient way?
Neil Watson
watson-wilson.ca
In reply to Efficiently parsing a large file by neilwatson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |