I think your parsing of localtime would be a lot easier once you realize that it returns a list if used in a list context.
#print "Enter a timestamp in mm/dd/yyyy hh:mm:ss format: "; #chomp(my $stamp = <STDIN>); my $stamp = '11/02/2007 11:02:07'; # Split out various fields for timelocal my($date, $time) = split / /, $stamp; my($month, $day, $year) = split /\//, $date; my($hour, $minute, $second) = split /:/, $time; # Both timelocal and localtime understand month as in 0 - 11 range $month -= 1; # Get time value in seconds since Epoch with timelocal my $now = timelocal($second,$minute,$hour,$day,$month,$year); # Add padding (this will become interactive) my $paddednow = $now + 300; my @padded_time = localtime $paddednow; $padded_time[5] += 1900; # year $padded_time[4]++; # month printf "$stamp + 5 minutes is %02d/%02d/%d %02d:%02d:%02d\n", @padded_time[4,3,5, 2,1,0]; # 11/02/2007 11:02:07 + 5 minutes is 11/02/2007 11:07:07
This is a fairly easy way to do this, but one of the date modules that have already been mentioned might make it even easier.
In reply to Re: Attack of the killer timestamps
by kyle
in thread Attack of the killer timestamps
by chexmix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |