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"; }
/oliver/

In reply to Re: More Date Conversion Happiness, Part 2 by neuroball
in thread 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.