in reply to Re^3: How to return a two dimensional array from a function in Perl?
in thread How to return a two dimensional array from a function in Perl?

One practice is more likely to eventually burn you than the other.

Please correct me if I'm wrong: The important point about choosing between "and/or" vs. "&&/||" involves their differences in precedence relative to other operators (especially the "comma operator"); the classic example (often seen in SoPW questions) being:

open $fh, "<", $filename || die "oops!"; # should use "or" here # (or else put parens around the args for the " +open()" call)
But the "burn" only happens when you use  &&/|| in a context where  and/or would be needed to do the right thing. In contrast, I can't think of any context appropriate for  &&/|| such that  and/or wouldn't serve equally well.

If you can find a context where  &&/|| produce an intended result and replacing them with  and/or produces a different (incorrect) result, that would be remarkably informative (and surprising, I think). NB: No fair making up obfu examples that depend on l-to-r vs. r-to-l differences -- people who get into that kind of trouble need other kinds of help and advice.

I'm guessing that BrowserUK has a similar view, and the reason we're both giving you grief about this is that you seem to be suggesting there are situations where using  and/or should be disfavored or unadvisable, whereas B and I would rather say that the better advice is "when in doubt, use  and/or" (which is what the OP seemed to be doing in the first place).

Replies are listed 'Best First'.
Re^5: How to return a two dimensional array from a function in Perl?
by ikegami (Patriarch) on Nov 03, 2008 at 21:43 UTC

    If you can find a context where &&/|| produce an intended result and replacing them with and/or produces a different (incorrect) result, that would be remarkably informative

    Easy. Consider rewriting

    if ($a == 1 or $b == 2) { ... }

    so that a variable is used to hold the condition.

    my $cond = $a == 1 or $b == 2; XXX if ($cond) { ... }

    Why write the same expression two different ways depending on context?