You should listen to the other monks who directed you to modules. But I wanted to take a stab at doing it in a regex. This code seems to work:
#!perl -w use strict; for my $y ( 1753 .. 9999 ) { for my $m ( 1 .. 12 ) { for my $d ( 1 .. 31 ) { my $date = sprintf "%04d/%02d/%02d", $y, $m, $d; if ( $date !~ m/^ ######################## # Year ([2-9]\d{3}|1[89]\d\d|17[6-9]\d|175[3-9]) \/ ##################### # Month (0[1-9]|1[0-2]) \/ ##################### # Day ( 0[1-9]|1\d|2[0-8]| # 01 - 28 (?<=(?:0[13578]|10|12)\/)(?:29|3[01])| # to 31 (?<=(?:0[469]|11)\/)(?:29|30)| # to 30 (?<=(?: (?:2[048]|3[26]|4[048]|5[26]|6[048]|7[26]|8[048]|9[26])00| \d\d(?:0[48]|1[26]|2[048]|3[26]|4[048]|5[26]|6[048]|7[26]|8[048]|9 +[26])\/02\/) )(?:29) # Leap year ) ######################## $/x ) { print "$date is invalid\n"; } # Else $1 == year, $2 == month, $3 == day }}}
Of course, different countries switched to the Gregorian calendar at different dates, so you really need a module to get it right. My favorite tome on the topic is "Calendrical Calculations" by Edward M Reingold and Nachum Dershowitz.

Update: I realized that I made a mistake listing leap-years. I've now fixed that, but it further demonstrates why a module is better.


In reply to Re: regular expression help by Adam
in thread regular expression help by Anonymous Monk

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.