Is your question about style, or about behavior? There's nothing surprising to me about the behaviors you're describing, but maybe there's an expectations vs reality gap.
You can use Devel::Peek to inspect the actual contents of a scalar.
You can use perldata to learn about what Perl sees as truth and falsehood.
You can refer to perlop to see the precedence list, where || is lower than +.
You can use perl -MO=Deparse,-p,-x9 -e 'print "we have ", ($fo + 2 || 8), " beans";' to see how that parses, and how precedence rules apply. That last one produces:
perl -MO=Deparse,-p,-x9 -e 'print "we have ", ($fo + 2 || 8), " beans" +;' print('we have ', (($fo + 2) || 8), ' beans'); -e syntax OK
Dave
In reply to Re: conditional print. Is correct to use it?
by davido
in thread conditional print. Is correct to use it?
by pvaldes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |