With all of your suggestions on my intro Perl class assignment (see that OP here), I have come up with the following code...it is a blend of code, pseudocode, and otherwise - this is only a skeleton (and the regexes are purely off the top of my head, but they remind me what each has to do).

I decided to do the month conversions all in one hash, rather than do conversions in 2 or more steps (i.e. why 8, 08, and aug are all in one hash.) Since there weren't that many choices the table didn't get too large in this case.

So all I'm writing about is to see if I'm on the right track, get opinions, suggestions, constructive criticism, or whatever. (bearing in mind it's a skeleton)(also bearing in mind that at this stage I will tend to write things out more explicitly, rather than as tersely as they could be).

Thanks in advance!
#!usr/bin/perl #Script to parse dates such as the following: #Apr 8 1984, Apr 08 84, 4/8/84, 04/08/84, 08 Apr 1984 use warnings; use strict; #declare my vars and make sure they're empty my $MM = $DD = $YY = $YYYY = (); #take in date at command line and make text lowercase chomp (my $date = <>); $date = lc ($date); #parse Apr 8 1984 if ($date =~ /^\[a-zA-Z]{3}\s\d\s\d{4}$/){ split $date and assign each part to $MM $DD and $YYYY; output ($MM, $DD, $YYYY); #parse Apr 08 84 } elsif ($date =~ /^\[a-zA-Z]{3}\s\d{2}\s\d{2}$/) { split $date and assign each part to $MM $DD and $YY; convert $YY to 4 digits and assign to $YYYY; output ($MM, $DD, $YYYY); #parse 4/8/84 } elsif ($date =~ /^\d\/\d\/\d{2}$/) { split $date and assign each part to $MM $DD and $YY; convert $YY to 4 digits and assign to $YYYY; output ($MM, $DD, $YYYY); #parse 04/08/84 } elsif ($date =~ /^\d{2}\/\d{2}\/\d{2}$/) { split $date and assign each part to $MM $DD and $YY; convert $YY to 4 digits and assign to $YYYY; output ($MM, $DD, $YYYY); #parse 08 Apr 1984 } elsif ($date =~ /^\d{2}\s\[a-zA-Z]{3}\s\d{4}$/) { split $date and assign each part to $MM $DD and $YYYY; output ($MM, $DD, $YYYY); #contingency plan } else { print "your date is not of a recognizable format...good day.\n"; } sub output { #take in $MM $DD $YYYY with @_, parse $MM with %months #and print "fullmonth day, year" to STDOUT my %months = ( jan => January feb => February mar => March apr => April may => MAY jun => June jul => July aug => August sep => September oct => October nov => November dec => December 1 => January 2 => February 3 => March 4 => April 5 => MAY 6 => June 7 => July 8 => August 9 => September 10 => October 11 => November 12 => December 01 => January 02 => February 03 => March 04 => April 05 => MAY 06 => June 07 => July 08 => August 09 => September) print "$MM's{value} $DD's{value}, $YYYY's{value}\n"; }

In reply to More Date Conversion Happiness, Part 2 by ctp

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.