in reply to Re^2: 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?

What practical difference is there between this:

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

What exactly is the difference between a "statement" and an "expression"?

I suppose it'd be safer to look at whether the program's flow is being controlled or not. or next, or return, or die, etc.

Replies are listed 'Best First'.
Re^4: How to return a two dimensional array from a function in Perl?
by graff (Chancellor) on Nov 03, 2008 at 19:31 UTC
    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).

      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?