Subject: | Race condition in SYNOPSIS code |
my $seconds = (localtime)[2]*3600 + (localtime)[1]*60 + (localtime)[2];
Bad idea. Multiple calls to time(), meaning the hour or minute may change in between leading to inconsistent results.
Much better is:
my $now = time;
my $seconds = (localtime $now)[2]*3600 + (localtime $now)[1]*60 + (localtime $now)[2];
Or maybe
my ( $sec, $min, $hr ) = (localtime)[0..2]; my $seconds = $hr*3600 + $min*60 + $sec;
Or other variations on a theme.
--
Paul Evans