The following variant uses the "return the true value" property of || to set a variable if it is currently false. It also uses next with a modifier to reduce nesting by a level.
The bug fix is to let the while loop run one more itteration after finding the end of the file.
use strict; my $date; my $lastdate; while (($date = <DATA>) or $lastdate){ $lastdate ||= $date; next if $lastdate eq $date; # print $lastdate report here print "Line $. ends date $lastdate"; $lastdate = $date; }
__DATA__ 10 10 10 11 11 11 12 12 12 Line 4 ends date 10 Line 7 ends date 11 Line 9 ends date 12
Update: add bug fix explanation
In reply to Re: Parsing log files
by GrandFather
in thread Parsing log files
by cajun
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |