I couldn't get your code and Time::Local to invalidate Feb. 31, 2003 08:40 by passing a ref to ('023103','08:40') so I whipped this up. As you can see, I choose to use die statements as opposed to the print and exit combo.

use Date::Calc qw(check_date check_time); our $DEBUG = 1; # set to 0 to disable print "woohoo!\n" if valid( ['033103','12:59'] ); # March 31, 2003 12: +59 valid print "w00t!\n" if valid( ['022803','13:00'] ); # February 28, 20 +03 13:00 valid print "Yippee!\n" if valid( ['023103','08:40'] ); # February 31, 2003 +8:40 invalid sub valid { my $ref = shift; my $date = shift @$ref; my $time = shift @$ref; die "Invalid date format $date" unless $date =~ /(\d\d)(\d\d)(\d\d +)/; my ($month, $day, $year) = ($1, $2, $3); $year += ($year <= 69) ? 2000 : 1900; die "Invalid date $date" unless (check_date($year,$month,$day)); die "Invalid time format $time" unless $time =~ /(\d\d):(\d\d)/; my ($hour, $minute) = ($1, $2); die "Invalid time $time" unless (check_time($hour,$min,$sec)); print "$date $time is valid.\n" if $DEBUG; return 1; }

update: fixed $year update code


In reply to Re: Comedy of StdErrs by Mr. Muskrat
in thread Comedy of StdErrs by abitkin

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.