[EMAIL PROTECTED] schreef:

> I'm trying to write a subroutine that returns the full month name, for
> example January, or February when I call the subroutine and pass a
> scalar, for example $m that could have a value in one of the following
> format
>
> 1. three letter format, for example jan or feb, or
> 2. one or digit format for example "01" or "1" for january


#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;

my @m = qw(
  NUL
  January February March
  April   May      June
  July    August   September
  October November December
);

my %m2m;
for (my $i = 1; $i <= $#m; $i++) {
    $m2m{ lc substr $m[$i], 0, 3 } = $i;
};

print Dumper [EMAIL PROTECTED];

print Dumper \%m2m;

print "$_: $m[ $m2m{ $_ } ]\n" for keys %m2m;

print "$_: $m[ $_ ]\n" for 1 .. 12, "01" .. "12";

__END__

-- 
Affijn, Ruud

"Gewoon is een tijger."


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to