in reply to Attack of the killer timestamps

It seems to work (It chokes though on a year like 2202)

That is because localtime is based on the Unix concept of the number of seconds since the epoch of January 1, 1970 and has historically been represented as a 32 bit number which only goes up to the year 2038.

This may work better:

#!/usr/bin/perl use warnings; use strict; use POSIX qw/ mktime strftime /; # Get timestamp input from user print 'Enter a timestamp in mm/dd/yyyy hh:mm:ss format: '; chomp( my $stamp = <STDIN> ); my ( $month, $day, $year, $hour, $minute, $second ) = $stamp =~ m! (\d ++) / (\d+) / (\d+) \s+ (\d+) : (\d+) : (\d+) !x; # Get time value in seconds since Epoch with mktime my $now = mktime $second, $minute, $hour, $day, $month - 1, $year - 19 +00; my $realanswer = strftime '%m/%d/%Y %H:%M:%S', localtime $now + 300; print "$stamp + 5 minutes is $realanswer\n";

Replies are listed 'Best First'.
Re^2: Attack of the killer timestamps
by chexmix (Hermit) on Mar 20, 2008 at 20:51 UTC
    I especially like how this compresses and elides things -- it's FAR more Perl-y than what I wrote.

    I'm still very much learning how to speak/write this stuff in anything like an effective way.

      Well, being a poet with a really nice grasp of English vocabulary should assist in becoming a conversant to fluent Perl programmer. Perl is very sensitive to context and has a plethora of its own vocabulary. Some people in fact deride it for these things, but others revel in them. My impression of you from this thread is that if you apply yourself to learning Perl's vocabulary and grammar as you have to those of English, you will be a master. All it takes is time, effort, a bit of intelligence, and the ability to handle symbolic thought. You're clearly, then, well on your way. Take heart and take practice, and you'll be writing like an old hand soon.
        Thanks for this & I hope you are right. It would be great if I could find shiny new reasons to not regret the time I have spent with poetry and theatre. When I was a teacher I used to tell my students "nothing is wasted," and really _believe_ it, but I'd go off and have a bout of regret anyway over not having studied astronomy, or mathematics (or whatever). But there _really are_ are many roads to enlightenment.
      use Class::Date qw(date -DateParse); $Class::Date::DATE_FORMAT="%Y/%m/%d %H:%M:%S"; print date('2008/01/01 10:00:00') + 300, "\n", date('2008-01-01 10:00: +00') + '5m';


      update: golf opened ;)


      holli, /regexed monk/