print (1 ? 1 : 0) . 'x'

london.pm@welikegoats.com london.pm at welikegoats.com
Thu May 11 11:15:31 BST 2006


Run it with "use warnings;", and all is revealed...

--

On Thu, 11 May 2006, O'Shaughnessy, Jamie wrote:

>
> 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