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

There have been a few such examples that have been brought up by SoPW. I don't recall the details of any of them either, but it is pretty straightforward to build an example.

If you use the wrong operator (&& vs and) then a number of low precedence operators will not behave as you expect:
use strict; use warnings; print "&&: "; print 1 && 1 ? 0 : 1; print "\nand: "; print 1 and 1 ? 0 : 1;
This prints:
&&: 0 and: 1
So, if you don't mind your code doing completely unexpected things, then you don't need to distinguish between "&&" and "and".

Replies are listed 'Best First'.
Re^6: How to return a two dimensional array from a function in Perl?
by BrowserUk (Patriarch) on Nov 03, 2008 at 15:36 UTC
    a number of low precedence operators will not behave as you expect

    Um. No. They behave exactly as I expect in both cases. Which immediately puts paid to this strawman: So, if you don't mind your code doing completely unexpected things,.

    then you don't need to distinguish between "&&" and "and".

    S'funny. I don't recall anyone, neither I nor ikegami, suggesting that.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      They behave exactly as I expect in both cases.

      Your emphasis is most appropriate. Not everyone trips over the same traps. If you're immune to it, great!

        If you're immune to it, great!

        It's not a case of being immune. My response was a genuine case of what I immediately saw when I looked at the two alternatives. I'm aware of the uncomfortable precedence that afflicts the ternary operator, and spotted the deliberate error immediately.

        But that's a consequence of having been bitten enough times by the precedence of ternary that I generally bracket the condition (regardless of whether it is a simple or compound condition), and often bracket the entire ternary also.

        And therein underlies at least part of my point. Rules without reasons are worse than no rules at all. We learn my making our own mistakes. Advice can alert us to dangers, but blanket censor rarely works well.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.