in reply to Precedence of grep vs. ?:
See
Note that you have other options beside what you listed. I'd have chosen: $f= grep( /f/, @array ) ? 1 : 2;$ perl -MO=Deparse $f= grep {/f/} @array ? 1 : 2; <EOF> $f = grep({/f/;} @array ? 1 : 2);
You were on the right track as to the source of your problem with your node title (originally just "precedence"). To quote bits from "perldoc perlop":
which means that list operators bind tighter than ?: if you use parens but looser if you don't. - tye (but my friends call me "Tye")left terms and list operators (leftward) [...] right ?: [...] nonassoc list operators (rightward) [...] Terms and List Operators (Leftward) A TERM has the highest precedence in Perl. They include [...] any function whose arguments are parenthesized. [...] List Operators (Rightward) On the right side of a list operator, it has very low precedence, such that it controls all comma-separated expressions found there. The only operators with lower precedence are the logical operators "and", "or", and "not", which may be used to evaluate calls to list operators without the need for extra parentheses: open HANDLE, "filename" or die "Can't open: $!\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (tye)Re: Precedence of grep vs. ?:
by blackjudas (Pilgrim) on Oct 05, 2001 at 09:56 UTC |