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 !;
In reply to Re: Grep-Ternary Operator Question
by ikegami
in thread Grep-Ternary Operator Question
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |