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

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).

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: OR operator
by DrManhattan (Chaplain) on Apr 11, 2003 at 09:50 UTC
    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