in reply to last in a do while loop
does not compile, since the do does not know anything about the while.
So it compiles just fine.~/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
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: last in a do while loop
by ikegami (Patriarch) on Nov 03, 2006 at 15:48 UTC | |
by Jenda (Abbot) on Nov 03, 2006 at 20:50 UTC | |
by ikegami (Patriarch) on Nov 03, 2006 at 21:38 UTC | |
by Jenda (Abbot) on Nov 04, 2006 at 00:08 UTC | |
by JimmyDa (Initiate) on Jan 23, 2008 at 16:32 UTC | |
by ikegami (Patriarch) on Jan 23, 2008 at 21:49 UTC | |
| |
by rir (Vicar) on Jan 23, 2008 at 17:46 UTC |
In Section
Seekers of Perl Wisdom