Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Fellow Monks, I recently was writing a report that took date ranges and spit out purty Graphs, btw thanks for the responses to my GD::Graph q a few days ago. I wrote this little method to check the date and make sure that they are valid dates, ie you do not put in feb 31 or anything else that would be invalid. I would like to petition you all to look it up and down and see if I have forgotten anything, or if there is any tightening of the code that can be done. Just want to make sure that nothing slips through the perverbial crack. Here she is
sub dateCheck { my $date = @{{@_}}{qw/date/}; my $err = '0'; if ($date) { my $year = substr($date,0,4); my $month = substr($date,4,2); my $day = substr($date,6,2); my %month; $month{'01'} = "January"; $month{'02'} = "February"; $month{'03'} = "March"; $month{'04'} = "April"; $month{'05'} = "May"; $month{'06'} = "June"; $month{'07'} = "July"; $month{'08'} = "August"; $month{'09'} = "September"; $month{'10'} = "October"; $month{'11'} = "November"; $month{'12'} = "December"; my $errDate = "The date you supplied: $month{$month} $day, $year"; if (substr($date,7,1) eq "") { $err="The date you supplied does not contain enough digits!"; } elsif (($year < 1900)||($year > 2100)) { $err="$errDate, did not contain a valid year!"; } elsif (($month < 1)||($month > 12)) { $err="$errDate, did not contain a valid month!<br>"; } elsif (($day < 1)||($day > 31)) { $err="$errDate, did not contain a valid day!"; } elsif ("$month" eq "02") { my $leap = ($year-2000) % 4; if ($leap == 0) { if ($day > 29) { $err="$errDate, does not exist!<br>There are only 29 days in + $month{$month} $year."; } } elsif ($day > 28) { $err="$errDate, does not exist!<br>There are only 28 days in $ +month{$month} $year."; } } elsif ($month < 8) { if (($month % 2 == 0)&&($day > 30)) { $err="$errDate, does not exist!<br>There are only 30 days in $ +month{$month}."; } } elsif ($month > 8) { if (($month % 2 == 1)&&($day > 30)) { $err="$errDate, does not exist!<br>There are only 30 days in $ +month{$month}.."; } } } return $err; }
Thank you and have a nice day :). tradez

In reply to Date Checking module by tradez

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (5)
    As of 2014-09-17 00:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (54 votes), past polls