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
    The above code looks fine to me. But in this sort of case, I would have used an "if" statement to, in my opinion, further clarify things, this is a matter of sytle:
    if (grep {/\Q$choice\E/}@REPORT) { last READ_LOOP; }
    I don't know the whole loop structure, but as a matter of style, I would have put the ending condition up in the while(..) or whatever loop if practical.

    I agree with ikegami, why be stingy with ()? They are super cheap (insignificant compile difference) and make things clear.