Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Re: help on getting date

by arturo (Vicar)
on Jun 02, 2003 at 18:05 UTC ( #262443=note: print w/replies, xml ) Need Help??

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;


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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://262443]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2023-03-25 18:17 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (63 votes). Check out past polls.