When I run this program:
print(rand*100)
I get values from [0,1) range.
But for this:
print(100*rand)
I get values from [0,100) range.
What is precedence here? and why first expression does not return values from [0,100) range?
On
You can always use B::Deparse to see how Perl is parsing an expression.
$ perl -MO=Deparse -e'print(100*rand)'
print 100 * (rand);
-e syntax OK
$ perl -MO=Deparse -e'print(rand*100)'
print rand *100;
-e syntax OK
randhas two syntax:randrand EXPRIf what follows
randcan be the start of an expression (EXPR), Perl assumes you are using the latter form.*can start anEXPR, sorand*...is parsed asrand EXPR. This means thatrand*100is equivalent torand(*100).