in reply to Grep-Ternary Operator Question
Precedence issue, so use parens to disambiguate.
grep /testme/, @array ? qq! yes ! : qq! no !
means
grep /testme/, ( @array ? qq! yes ! : qq! no ! )
You want
grep(/testme/, @array) ? qq! yes ! : qq! no !
or
(grep /testme/, @array) ? qq! yes ! : qq! no !
Update: AnomalousMonk mentioned "Perhaps make clear that both solutions need to be enclosed in original set of parens to work."
Replacing
grep /testme/, @array ? qq! yes ! : qq! no !
with
(grep /testme/, @array) ? qq! yes ! : qq! no !
means
my $string = qq! first ! . ( grep /testme/, @array ? qq! yes ! : qq! no ! ) . qq! end !;
becomes
my $string = qq! first ! . ( (grep /testme/, @array) ? qq! yes ! : qq! no ! ) . qq! end !;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Grep-Ternary Operator Question
by ww (Archbishop) on Oct 05, 2010 at 21:12 UTC | |
by ikegami (Patriarch) on Oct 05, 2010 at 21:31 UTC | |
by ww (Archbishop) on Oct 05, 2010 at 23:32 UTC |