in reply to Re: Re: Re: OR operator
in thread OR operator

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
(jeffa) 5Re: OR operator
by jeffa (Bishop) on Apr 10, 2003 at 21:15 UTC
    I fail to see the big deal in using $_ on the left or the right. I mean, tomAYto tomAHto. Where i see people making a big deal about this is with code that uses the numerical comparison operator, which can easily be mistyped, yielding an assignment operator:
    perl -le'print "Yep" if $_ = 42'
    Switch the two operands and you get a syntax error:
    perl -le'print "Yep" if 42 = $_'
    Me? I still use the former, because if i make that mistake i want to be punished ;) ... but i can definitely see recommending the later to someone else. But ... as for 'readabilty', i say use whichever makes the most sense to the author.

    Is today's date April 10th or the 10th of April? ;)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Re: Re: Re: Re: OR operator
by DrManhattan (Chaplain) on Apr 10, 2003 at 17:13 UTC
    I think we're actually on the same page here. In my mind, $color is "this thing" and $_ is e.g. "blue". The code asks, "Is $color red", "Is $color green", or "Is $color blue?" To me, $_ eq $color reads, "Is red $color", "Is blue $color", or "Is green $color?" which seems backwards.

    -Matt

      I think we're actually on the same page here. In my mind, $color is "this thing" and $_ is e.g. "blue".

      But "for" topicalizes. $_ is the topic. $_ is more variable than $color, $_ is the thing.

      for (qw/green blue red/) { if ($color eq $_) { ... } } for each of green, blue and red: if the color is it, do something

      for (qw/green blue red/) { if ($_ eq $color) { ... } } for each of green, blue and red: if it is the color, do something

      I read $_ as "the thing" or "it". How do you read $_?

      Juerd
      - http://juerd.nl/
      - spamcollector_perlmonks@juerd.nl (do not use).
      

        I read $_ as "the thing" or "it". How do you read $_?

        The original poster wanted this:

        if ($color eq "blue || $color eq "red" || $color eq "green")
        My second post essentially stated ...
        if ($color eq $_)
        ... and dynamically replaced $_ with "blue", "red", or "green". Thus to me, $_ eq $color is like stating ...
        if ("blue eq $color || "red" eq $color || "green" eq $color)
        ... which isn't intuitive.

        -Matt