print (1 ? 1 : 0) . 'x'
O'Shaughnessy, Jamie
jamieosh at amazon.co.uk
Thu May 11 10:59:01 BST 2006
print (1 ? 1 : 0) . 'x';
What do you expect this would print?
I expected the output would be "1x" - the ?: evaluates to 1, the ()s are needed because . Is higher precedence than ?: so you end up with 1 . 'x' as the parameter to print - hence print "1x".
However it doesn't, it just prints "1".
Can anyone explain what is happening here?
Changing the code to:
print (1 ? 1 : 0), 'x';
Also does the same, yet:
Print 1 ? 1 : 0, 'x';
Does print out "1x".
Also, taking the original code and assigning it to a variable:
my $x = (1 ? 1 : 0) . 'x';
print $x;
Also prints out "1x"
???
Cheers,
Jamie
More information about the london.pm
mailing list