Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %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
- );
- $mon2num{"jan"}
- my %number_for = (
- jan => 1,
- feb => 2,
- #etc...
- );
- #...
- do_something_with($number_for{$month})
- my %month; @month{qw/jan feb mar apr may jun
- jul aug sep oct nov dec/} = (1 .. 12);
- my %month_num = do { my $i = 1; map {; $_ => $i++ } (
- qw( jan feb mar apr may jun jul aug sep oct nov dec )
- ) };
- my %month_num;
- $month_num{ $_ } = 1 + keys %month_num for (
- qw( jan feb mar apr may jun jul aug sep oct nov dec )
- );
- my %month_num = do {
- my @month = qw( jan feb mar apr may jun jul aug sep oct nov dec );
- zip2( 1 .. 1+$#month, @month );
- };
- # create a lookup table of month abbreviations to month numbers
- my %month_abbr_to_number_lkup = (
- jan => 1,
- feb => 2,
- mar => 3,
- apr => 4,
- may => 5,
- jun => 6,
- jul => 7,
- aug => 8,
- sep => 9,
- oct => 10,
- nov => 11,
- dec => 12,
- );
- # get the number for a month
- my $number = $month_abbr_to_number_lkup{$abbr}
- || die "Could not convert month abbreviation '$abbr' to a number.";
- %mon_2_num = (jan => 1,
- feb => 2,
- ...);
- $month_number = $mon_2_num{lc($month_name_abbrev)};
- @month{qw(jan feb mar apr may jun jul aug sep oct nov dec)} = 1..12;
- my @months = qw(Jan Feb Mar Apr May Jun
- Jul Aug Sep Oct Nov Dec);
- my %monthnum = map { $_ => $months[ $_ - 1 ] } 1..12;
Add Comment
Please, Sign In to add comment