Kevin Pfeiffer wrote:
> 
> (Forgive the excitement)
> 
> I just reversed the %n2m construct - the original builds a hash using map
> that lets you convert numbers to months, etc. (I probably found it here).
> 
> In keeping with my feeling that with 'map' one can do almost anything (if I
> knew how) I'm happy to have managed to build something using 'map' (without
> external help I mean). Seems easy, now. ;-)
> 
> # months into numbers...
> 
> $month = "Jan"  # for example
> 
> my %m2n;
> my $x = "00";
> 
> map { $m2n{$_} = ++$x } qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
> 
> my $mon = $m2n{$month};
> 
> [snip]

You don't really need to use map, you can just assign the keys and values directly:

my %m2n = qw(Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06 Jul 07 Aug 08 Sep 09 Oct 10 Nov 
11 Dec 12);

If you want to use map then you should assign the list returned from map to your hash:

my $x = '00';
my %m2n = map { $_ => ++$x } qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);


If you want to convert a number to a month name here is some serious magic from Randal 
L. Schwartz.

sub magic {substr gmtime 259e4*(-.5+shift),4,3}


Or some more traditional methods:

sub mon_name { [qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/]->[-1+shift] }

sub mon_name { substr"JanFebMarAprMayJunJulAugSepOctNovDec",3*(-1+shift),3 }



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to