in reply to conditional print. Is correct to use it?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: conditional print. Is correct to use it?
by pvaldes (Chaplain) on Oct 27, 2020 at 21:45 UTC | |
by AnomalousMonk (Archbishop) on Oct 28, 2020 at 19:29 UTC |