Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the easiest or most effective way to convert month's abbreviation to a number in Perl? (ie "jan" to 1)

If I import a library to use a method, would it be worth it? Does importing take up a lot of memory?

like image 485
jcee14 Avatar asked Oct 27 '08 22:10

jcee14


2 Answers

borrowed from here

%mon2num = qw(
    jan 1  feb 2  mar 3  apr 4  may 5  jun 6
    jul 7  aug 8  sep 9  oct 10 nov 11 dec 12
);

and to retrieve

$mon2num{"jan"}
like image 95
Oskar Avatar answered Sep 21 '22 04:09

Oskar


Here is yet another way to do it:

my %month; @month{qw/jan feb mar apr may jun
                     jul aug sep oct nov dec/} = (1 .. 12);
like image 40
Robert Krimen Avatar answered Sep 19 '22 04:09

Robert Krimen