UPDATE 2 - 1-11-04, 7:53PM - I have finished it...it works as required. I will post the final code soon and let everyone beat up on it :-)
========================

update - to see the posts leading up to this script check this node out

Okay...be forewarned, it is verbose as heck! But at this stage of my learning I don't want to distill it down...we'll get to that after I turn in the working script and we can really have at it.

I am having brainfreeze on the subroutine, as to how best to collect the three values, and then parse the month variable thru my hash...I'm still not so good with hashes.

Next to last thing, Perl tells me that I have an illegal octal digit 8, and 9, in my hash. How do I escape those? Or am I doing something else wrong there?

Last thing, the 5th regex doesn't work...I've been going round and round with it, but nothing I've tried makes it work. It's probably something really dumb, but my dumb luck seems to be running low today. The other 4 seem to work fine. BTW - when I paste in my code I get whitespaces, that aren't really there in my script, after brackets and braces. Ah well...as always, any and all help is greatly appreciated!

#!usr/bin/perl #Script to parse dates with the following formats: #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 print "\n\n\n\n"; print "Date Converter, v1.0\n"; print "this program assumes that a year from 10 to 99 is in the 1900's +\n"; print "and that a year from 00 to 09 is in the 2000's\n"; print "please enter a date\n"; chomp (my $date = <>); $date = lc ($date); if ($date =~ /[a-zA-Z]{3}\s\d{1,2}\s\d{4}/) #parse Apr 8 1984 { my @dateparts = split (/\s/ , $date); $MM = $dateparts [0]; $DD = $dateparts [1]; $YYYY = $dateparts [2]; output ($MM, $DD, $YYYY); } elsif ($date =~ /[a-zA-Z]{3}\s\d{2}\s\d{2}/) #parse Apr 08 84 { my @dateparts = split (/\s/ , $date); $MM = $dateparts [0]; $DD = $dateparts [1]; $YY = $dateparts [2]; if (10 <= $YY && $YY <= 99) {$YYYY = $YY + 1900} elsif (0 <= $YY && $YY <= 9) {$YYYY = $YY + 2000} output ($MM, $DD, $YYYY); } elsif ($date =~ /\d\/\d\/\d{2}/) #parse 4/8/84 { my @dateparts = split (/\// , $date); $MM = $dateparts [0]; $DD = $dateparts [1]; $YY = $dateparts [2]; if (10 <= $YY && $YY <= 99) {$YYYY = $YY + 1900} elsif (0 <= $YY && $YY <= 9) {$YYYY = $YY + 2000} output ($MM, $DD, $YYYY); } elsif ($date =~ /\d{2}\/\d{2}\/\d{2}/) #parse 04/08/84 { my @dateparts = split (/\// , $date); $MM = $dateparts [0]; $DD = $dateparts [1]; $YY = $dateparts [2]; if (10 <= $YY && $YY <= 99) {$YYYY = $YY + 1900} elsif (0 <= $YY && $YY <= 9) {$YYYY = $YY + 2000} output ($MM, $DD, $YYYY); } elsif ($date =~ /\d{1,2}\s[a-zA-Z]{3}\s\d{4}/) #parse 08 Apr 1984 { my @dateparts = split (/\s/ , $date); $DD = $dateparts [0]; $MM = $dateparts [1]; $YYYY = $dateparts [2]; output ($MM, $DD, $YYYY); } else #contingency plan { print "your date is not of a recognizable format...good day.\n"; } #take in $MM $DD $YYYY, parse $MM with %months #and print "fullmonth day, year" to STDOUT sub output { my @outputdates = @_; 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" ); #unfinished print "$outputdates[1], $outputdates[2]\n"; }

In reply to more date conversion happiness, part 3 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.