missingthepoint has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, monks.
Let's say I have:
my %foo = map( $_ => 2*$_, 1..10 ); use Data::Dumper; print Dumper(\%foo);
... and I (naively) expect output like:
$VAR1 = { '6' => 12, '3' => 6, '7' => 14, '9' => 18, '2' => 4, '8' => 16, '1' => 2, '4' => 8, '10' => 20, '5' => 10 };
But that's not the result. It looks like it's being parsed as:
my %foo = map( $_, 2 * $_, 1..10 )... where all but the first argument are flattened into a single list.
Why doesn't Perl DWIM here? In general terms, what's an EXPR and what's not (and why can't $_ => 2*$_ be one)?
Cheers,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: map EXPR - what's an EXPR?
by moritz (Cardinal) on Nov 28, 2008 at 12:08 UTC | |
|
Re: map EXPR - what's an EXPR?
by johngg (Canon) on Nov 28, 2008 at 15:05 UTC | |
|
Re: map EXPR - what's an EXPR?
by ikegami (Patriarch) on Nov 28, 2008 at 17:32 UTC | |
|
Re: map EXPR - what's an EXPR?
by parv (Parson) on Nov 28, 2008 at 13:24 UTC |