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

a strange $_ "mis"-behavior in map

Thread Next
From:
Stas Bekman
Date:
October 9, 2003 00:30
Subject:
a strange $_ "mis"-behavior in map
Message ID:
3F850E5A.5090205@stason.org
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.

Originally I planned to do:

  ... = map { "key_$_" => 1 } (a..c);

It seems to happen with all perls.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Thread Next


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