in reply to Final date conversion happiness script

I think the biggest thing I would have approached differently (other than using a CPAN module to do date work) is to divide the problem into parts and have code to perform each part.
# input: chomp(my $date = <>); # parse, return numeric year,month,day or empty list on error if (my ($y,$m,$d) = split_date($date)) { # print out in Month dd yy format print "Date is: ", format_date($y,$m,$d), "\n"; } else { print "invalid date: $date; please try again\n"; }
It doesn't make as much sense to have part of your conversion done in the main code and part done in a subroutine. Ditto for printing an error message in the main code or the successful formatting in a sub.

Update: make comment agree with code re: order of returned values; said parsing but meant conversion

Replies are listed 'Best First'.
Re: Re: Final date conversion happiness script
by ctp (Beadle) on Jan 13, 2004 at 00:21 UTC
    I think the biggest thing I would have approached differently (other than using a CPAN module to do date work)

    I think we are heading into the part of the class where we can do just that...gotta get that foundation stuff outta the way tho

    is to divide the problem into parts and have code to perform each part.

    Yea - I recognize that I did this script in a sort of "conversant" style (or some other word that makes more sense) in order to help me understand how to make it work. I'm just now starting to get more comfortable with dividing things into discrete functions, and subroutines. Now I just have to put that more into practice.