http://qs1969.pair.com?node_id=262443


in reply to Re: help on getting date
in thread help on getting date

First off I want to emphasize that you're right on all the really important points. The nit I will pick is that "need" is kind of a strong word, given that there's a pretty simple way to convert MM-DD-YYYY to YYYY-MM-DD format, even if it's not widely capable like a Date::* module:

# assumes you have 0-padded dates, but if you don't you can change # the \d\d's to \d\d?'s , and do an appropriate sprintf. my @ymd = map { my ($m, $d, $y) = $_ =~ /(\d\d)-(\d\d)-(\d{4})/; "$y- +$m-$d"; } @dmy;

HTH

If not P, what? Q maybe?
"Sidney Morgenbesser"

Replies are listed 'Best First'.
Re: Re: Re: help on getting date
by boo_radley (Parson) on Jun 02, 2003 at 19:33 UTC

    why bother with the temporary variables, especially inside map? Heck, you'd also screen out a small subset of invalid data.
    print  map {$_ =~ /(\d\d)-(\d\d)-(\d{4})/ && "$3-$1-$2"; } ("01-02-1999");
    of course, using this kind of code, you'd need to make sure that your dataset's valid -- you won't get Date::Manip's heavy duty "Am I valid datetime or not" routines.