2 ms·
I've never seen: $CONDITION && $TRUE_CASE || $FALSE_CASE used as a Perl idiom in lieu of: $CONDITION ? $TRUE_CASE : $FALSE_CASE I can't claim to have wo
by pyre 13y ago
I've never seen:
$CONDITION && $TRUE_CASE || $FALSE_CASE
used as a Perl idiom in lieu of:
$CONDITION ? $TRUE_CASE : $FALSE_CASE
I can't claim to have worked with Perl much prior to Perl 5.6/5.8 though, so it may have been an older idiom (though I doubt it as one of Perl's influences was Awk, which also has a C ternary operator, IIRC).
That said, using truthy/falsey values in Python doesn't seem super common. I surprised a couple of interviewers by doing that while implementing some tree manipulation functions.