Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in perl(v5.14.2), why is map{+0,0}() correct but map{0,0}() not? [duplicate]

Tags:

perl

It seems that perl treat {+0,0} as a BLOCK and {0,0} an EXPR But why? Is that a special provision?

If I want to make sure that the {} is an anonymous hash whatever the braces contain, do I have to put a `+' before {} ?

thanks.

like image 360
exprosic Avatar asked May 17 '13 11:05

exprosic


1 Answers

Why? Because it could be either, and the parser doesn't look far enough ahead to know for sure by the time it needs to decide.

Do you have to put a '+' before {} to have it be treated as an anonymous hash constructor regardless of the contents of the {}? Yes.

like image 150
ysth Avatar answered Nov 15 '22 05:11

ysth