in reply to Reading log file for current date
You should use warnings and strict. It will pick up typos such as close FILE when you meant close FH
The whole date generation can be done more simply with sprintf
sub get_cur_time { # Use a slice to get just the bits I need my ( $Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay ) = (localtime)[ 0 .. 5 ]; return sprintf '%0.2d/%0.2d/%0.4d %0.2d:%0.2d:%0.2d', $Month + 1, +$Day, $Year + 1900, $Hour, $Minute, $Second; }
You also need to test if the line matches $aDate
I put $aDate between \Q and \E so that any character that has a special meaning in the regex is escaped.while( my $line = <FH> ) { if ( $line =~ /\Q$aDate\E/ ) { print $line; } }
|
|---|