in reply to Alas poor grep, I thought I knew him well..
Irrespective of the values of $choice and @REPORT, the last statement is always reached (and executed).
I doubt that. I think you'll find the number of elements in @REPORT matters, since
grep /\Q$choice\E/, @REPORT && do { last READ_LOOP; };
means
grep /\Q$choice\E/, ( @REPORT && do { last READ_LOOP; } );
&& has higher precedence than the list comma.
Deparse's -p option would have helped you.
>perl -MO=Deparse,-p -e"grep /\Q$choice\E/, @REPORT && do { last READ_ +LOOP; };" grep(/\Q$choice\E/, (@REPORT && do { last READ_LOOP })); -e syntax OK
Parens can be used to disambiguate, and switching to using and will given you the precedence you desire. I also removed the do since it's useless here.
grep(/\Q$choice\E/, @REPORT) # OK && last READ_LOOP;
grep /\Q$choice\E/, @REPORT # OK and last READ_LOOP;
grep(/\Q$choice\E/, @REPORT) # OK and last READ_LOOP;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Alas poor grep, I thought I knew him well..
by Marshall (Canon) on May 08, 2009 at 17:34 UTC |