in reply to Multiple date format
The following works for the range of formats you have given.
use strict; use warnings; my %months = ( january => 'jan', february => 'feb', march => 'mar', april => 'apr', may => 'may', june => 'jun', july => 'jul', august => 'aug', september =>'sep', october => 'oct', november => 'nov', december => 'dec', ); my %monthCvt = ( jan => 1, feb => 2, mar => 3, apr => 4, may => 5, jun => 6, jul => 7, aug => 8, sep => 9, oct => 10, nov => 11, dec => 12, ); while (<DATA>) { chomp; $_ = lc $_; # Strip leading spaces s/\s*//; # Normalize month s/([a-z]+)/$months{$1} || $1/e; # Normalize punctuation s|[ -/,.\\]+| |g; # Normalize order: month day year s|^(\d+)\s([a-z]+)|$2 $1|; # Extract fields my ($month, $day, $year) = /(\w+) (\d+) (\d+)/; # Month to numeric form if required $month = $monthCvt{$month} if $month !~ /\d/; print "$month/$day/$year\n"; } __DATA__ Sep 29 2005 Jun 30, 2003 December 15 2005 December 31, 2004 06-Dec-2005 10-19-2005
Prints:
9/29/2005 6/30/2003 12/15/2005 12/31/2004 12/06/2005 10/19/2005
|
|---|