develooper Front page | perl.perl5.porters | Postings from October 2003

Re: a strange $_ "mis"-behavior in map

Thread Previous
From:
Rafael Garcia-Suarez
Date:
October 9, 2003 00:33
Subject:
Re: a strange $_ "mis"-behavior in map
Message ID:
20031009092644.6157dd84.rgarciasuarez@free.fr
Stas Bekman wrote:
> May be it's just late and I need to sleep over it, but consider:
> 
> map {           $_  => 1  } (a..c);
> map { $x = $_; "$x" => 1  } (a..c);
> map {         ("$_" => 1) } (a..c);
> map {          "$_" => 1  } (a..c);
> 
> the first three lines are fine, the fourth produces an error:
> 
>    syntax error at /tmp/oops line 4, near "} ("
> 
> what's wrong with $_ stringification as the key? and it only happens without 
> () around the key/value pair.

Parsing issue : ambiguity blocks vs hash refs.
See perldoc -f map (but I'm sure you know this already). Good night :)

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About