in reply to Re: Date String Conversion?
in thread Date String Conversion?

Save yourself :-)
#!/usr/bin/perl use strict; use warnings; my %months = ( Jan => 1, Feb => 2, Mar => 3, # ..... ); my $str = shift; my($day, $mon, $year) = split /(\D+)/, $str; printf "%02d-%02d-%s\n", $months{$mon}, $day, "20$year";
I don't feel good with the 20$year part, though. It reminds me of the 19100 syndrome :-)

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Replies are listed 'Best First'.
Re^3: Date String Conversion?
by parv (Parson) on Jun 09, 2007 at 02:12 UTC

    By your "Save yourself" I was thinking you were going to build the month name-number hash more lazily...

    my %months; @months{qw( jan feb mar apr may jun jul aug sep oct nov dec )} = ( 1 .. 12 );
      Believe it or not, that was my initial draft in one-liner version. But I then decided to write it in a full script, and followed citromatik's style in hash building with a little modification. Don't get me wrong, I do like slices :-) OTOH, I intentionally focused on the input parsing and output printing parts, where citromatik's version seems to suffer from, in efforts and clarity.

      Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!