in reply to Re: strange syntax error with map
in thread strange syntax error with map
I'm not a big fan of the unary plus solution, since it's not easily understandable why the unary plus sometimes works or not.
Fun with Perl's parsing:
DB<100> map {+2,$_} 1..3 # +2 is not a hash key => (2, 1, 2, 2, 2, 3) DB<101> map {2,$_} 1..3 # 2 is a hash key ;; Not enough arguments for map at (eval 21)[multi_perl5db.pl:644] line 2, near "} 1" syntax error at (eval 21)[multi_perl5db.pl:644] line 2, near "} 1" DB<102> map {2,$_}, 1..3 # 2 is a hash key => ({ 2 => 1 }, { 2 => 2 }, { 2 => 3 }) DB<103> map {+2,$_}, 1..3 # +2 is not a hash key ;; syntax error at (eval 26)[multi_perl5db.pl:644] line 2, near "}," DB<104> map {+2 => $_}, 1..3 # +2 is not a hash key even with fat co +mma ;; syntax error at (eval 29)[multi_perl5db.pl:644] line 2, near "},"
so far so consistent, BUT
DB<105> map +{+2 => $_}, 1..3 # +2 IS A HASH KEY => ({ 2 => 1 }, { 2 => 2 }, { 2 => 3 }) DB<106> map +{+2 , $_}, 1..3 # +2 IS A HASH KEY even without => => ({ 2 => 1 }, { 2 => 2 }, { 2 => 3 })
see my point? :)
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: strange syntax error with map (unary plus)
by haukex (Archbishop) on Apr 09, 2017 at 17:48 UTC |