http://qs321.pair.com?node_id=582072


in reply to last in a do while loop

does not compile, since the do does not know anything about the while.
~/perl$ cat x do { charlie; last if bob; david; } while (alice); ~/perl$ perl -c x x syntax OK ~/perl$ perl -v This is perl, v5.6.1 built for i386-linux
So it compiles just fine.

What is not working, though, is the last. This is because the block introduced with do is neither a loop nor a bare block. Your statement is basically equivalent in structure to print foo while bar.

What you can do instead is a bare block, because you can use next, last, redo on a bare block:

LOOP: { charlie; last LOOP if bob; david; redo LOOP if alice; }

-- Hofmator

Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.