[Edinburgh-pm] syntax error weirdness

Rory Macdonald rory at employees.org
Fri Aug 5 01:38:00 PDT 2005


On Fri, 2005-08-05 at 00:58 +0100, David Baird wrote:
> dave at evesham$ perl -e 'map { $_,1 } "x"'
> dave at evesham$ perl -e 'map { "$_" } "x"'
> dave at evesham$ perl -e 'map { "$_",1 } "x"'
> syntax error at -e line 1, near "} "x""
> Execution of -e aborted due to compilation errors.
> dave at evesham$ perl -v
> 
> This is perl, v5.8.6 built for i386-freebsd-64int
> 
> Anybody know why the third line shouldn't compile? Just seems weird.

Cos perl is guessing (wrongly) that the contents of your { ... } is a
hash ref rather than a BLOCK.

perldoc -f map

There should be a paragraph talking about this in the above doc.

2005-08-05 09:36:12 $ perl -e 'map { "$_",1 } "x"'
syntax error at -e line 1, near "} "x""
Execution of -e aborted due to compilation errors.
2005-08-05 09:36:14 $ perl -e 'map { ("$_",1) } "x"'
2005-08-05 09:36:17 $ 

Rory

-- 
Rory Macdonald <rory at employees.org>


More information about the Edinburgh-pm mailing list