http://qs321.pair.com?node_id=11113255


in reply to Strange interaction between print and the ternary conditional operator

my $call_resp = print(1 ? 'yes' : 'no) . 'bar'; # yes print "\nprint() function returned: $call_resp\n"; # \nprint() funct +ion returned: 1bar\n

print returns a true value on success, and a false value if it failed. The parenthesis, the way you're using them, become the arg list for print. So you're asking Perl to print 'yes', and then to append 'bar' to the return response from print. This is almost equivalent, and may help explain what's happening:

(print 1 ? 'yes' : 'no') . 'bar';

A common disambiguation is +(...). I wasn't sure it would be appropriate when concatenating later, but I just verified that it works fine:

print +(1 ? 'yes' : 'no') . "bar\n"; # yesbar\n

Dave