in reply to Quick search-and-replace month names for numbers

I think you guys are making it too hard.

#!/usr/bin/perl my %month = ( JAN=>'01', FEB=>'02', MAR=>'03', APR=>'04', MAY=>'05', JUN=>'06', JUL=>'07', AUG=>'08', SEP=>'09', OCT=>'10', NOV=>'11', DEC=>'12' ); map { s/^(\w{3}).*/$month{uc $1}/; print(( ($_)?$_:'undef' ), "\n"); } @ARGV; __END__ %./foo january Dec Apr MAY xJun [3:27pm] 01 12 04 05 undef


s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}

Replies are listed 'Best First'.
Re^2: Quick search-and-replace month names for numbers
by ambrus (Abbot) on Mar 06, 2008 at 08:39 UTC

    Good, but it's possible to do it even simpler.

    perl -we 'use Date::Manip; for (@ARGV) { print UnixDate($_ . "/15","%m +\n") || "?\n"; }' january Dec 3 Apr MAY xJun

    Output:

    01 12 03 04 05 ?