Jenda Krynicky wrote:
> From: Kevin Pfeiffer <[EMAIL PROTECTED]>
> > In keeping with my feeling that with 'map' one can do almost
> > anything
>
> quite right, but
>
> > (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);
>
> you should not use map{}() in void context. map{}() is supposed to
> create a list, in this case you are not creating any. You are just
> looping through a list. You should use for/foreach for that:
>
> $m2n{$_} = ++$x
> for qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
>
> But the idea was good :-)

Don't worry Kevin! You can still use 'map' by getting the block
to calculate each key/value pair like this

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

HTH,

Rob




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

Reply via email to