OT Perl question
Matthew Seaman
m.seaman at plasm.demon.co.uk
Tue Jul 3 00:28:58 BST 2001
On Mon, Jul 02, 2001 at 06:31:51PM -0400, Will Macdonald wrote:
> Currently I have managed to split up each line and get the following
> values for date:
>
> 29/Jun/2001 09:01:27
>
> From what I can see from the MySQL docs, I need to convert this to :
> 29/06/2001 09:01:27
>
> I have found lots of CPAN stuff for going from mm to MMM, but not the
> other way round.
>
> Would using a hash array be best, ala:
> @month{"Jan","Feb","Mar".....} = ("01","02","03"...);
>
> print @month{"01"};
>
@foo is an array. You want %foo for a hash, or $foo{bar} to look
something up in a hash:
#!/usr/bin/perl
%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" );
$date = '29/Jun/2001 09:01:27';
$date =~ s@([A-Z][a-z][a-z])@$month{$1}@e;
print "$date\n";
Matthew
--
Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks
Savill Way
Tel: +44 1628 476614 Marlow
Fax: +44 0870 0522645 Bucks., SL7 1TH UK
More information about the Ukfreebsd
mailing list