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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.