in reply to Monk Specs.?

my $counter = 0; my $dateRX = qr/^$date/; # assuming $date is defined elsewhere while (<LOG>){ last if /$dateRX/; $counter++; } print LOGFILE $_ while (<LOG>); #assuming LOGFILE was opened earlier i +n your code
Regards.

Replies are listed 'Best First'.
Re: Re: Monk Specs.?
by ehdonhon (Curate) on Jan 16, 2002 at 22:30 UTC

    Only problem is that you are no longer incrementing counter after you encounter the date.

    my $counter = 0; my $dateRX = qr/^$date/; # assuming $date is defined elsewhere while (<LOG>){ last if /$dateRX/; $counter++; } while ( <LOG> ) { print LOGFILE; $counter++; }

    UPDATE: I assumed that $counter was actually doing something outside of the context of this code, maybe I should not have assumed that. If the only thing that counter is being used for is to assign the start date variable, then my revision above is un-neccessary. It should also be noted that in the original code, since counter is incremented before the regexp is checked, then the start date variable will always point to the first line AFTER the one that matched.