BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
Why does this work:
#! perl -slw use strict; use Data::Dumper; my $d = [ [[1,2], [3,4]], [[5,6], [7,8]] ]; my %hash = map{ my $key = "@{ $_->[ 0 ] }"; $key => $_ } @{ $d }; print Dumper \%hash; __END__ C:\test>junk.pl $VAR1 = { '5 6' => [ [ 5, 6 ], [ 7, 8 ] ], '1 2' => [ [ 1, 2 ], [ 3, 4 ] ] };
And this not?
#! perl -slw use strict; use Data::Dumper; my $d = [ [[1,2], [3,4]], [[5,6], [7,8]] ]; my %hash = map{ "@{ $_->[ 0 ] }" => $_ } @{ $d }; print Dumper \%hash; __END__ [ 4:49:09.65] C:\test>junk.pl syntax error at C:\test\junk.pl line 7, near "} @" Execution of C:\test\junk.pl aborted due to compilation errors.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Syntax error that I don't understand?
by ikegami (Patriarch) on Jul 03, 2008 at 04:01 UTC | |
by BrowserUk (Patriarch) on Jul 03, 2008 at 04:06 UTC | |
by Anonymous Monk on Jul 03, 2008 at 14:53 UTC |