There is not much more one can comment at until you come up with the first version of your script.
The only thing I can come up with is a better style of writting your code.
A coding style helps you to envision the code flow and also helps with tracking down simple one-off errors (I.e. a bracket to much, not enough brackets, ...).
You might want to read this article about perl style guidelines.
Example:
#!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); if ($date =~ /^\[a-zA-Z]{3}\s\d\s\d{4}$/) #parse Apr 8 1984 { split $date and assign each part to $MM $DD and $YYYY; output ($MM, $DD, $YYYY); } elsif ($date =~ /^\[a-zA-Z]{3}\s\d{2}\s\d{2}$/) #parse Apr 08 84 { split $date and assign each part to $MM $DD and $YY; convert $YY to 4 digits and assign to $YYYY; output ($MM, $DD, $YYYY); } elsif ($date =~ /^\d\/\d\/\d{2}$/) #parse 4/8/84 { split $date and assign each part to $MM $DD and $YY; convert $YY to 4 digits and assign to $YYYY; output ($MM, $DD, $YYYY); } elsif ($date =~ /^\d{2}\/\d{2}\/\d{2}$/) #parse 04/08/84 { split $date and assign each part to $MM $DD and $YY; convert $YY to 4 digits and assign to $YYYY; output ($MM, $DD, $YYYY); } elsif ($date =~ /^\d{2}\s\[a-zA-Z]{3}\s\d{4}$/) #parse 08 Apr 1984 { split $date and assign each part to $MM $DD and $YYYY; output ($MM, $DD, $YYYY); } else #contingency plan { print "your date is not of a recognizable format...good day.\n"; } #take in $MM $DD $YYYY with @_, parse $MM with %months #and print "fullmonth day, year" to STDOUT sub output { 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 Re: More Date Conversion Happiness, Part 2
by neuroball
in thread More Date Conversion Happiness, Part 2
by ctp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |