in reply to "last" not really outside loop block

do { ... } while 1;
is no different than
print ... while 1;

The while is a statement modifier. There's no loop block, and one is needed for redo, next and last to work.

A generic solution is to add a loop. Keep in mind that a bare block is a loop that executes once.

$a = 3; LOOP_ONCE: { do { last unless $a == 4; } while cond(); }

The label (LOOP_ONCE:) is descriptive and not necessary.

Replies are listed 'Best First'.
Re^2: "last" not really outside loop block
by spx2 (Deacon) on Jun 22, 2009 at 15:59 UTC

    Yeah , that's the work-around I've used also , I didn't like it , actually I hate it , but I'll have to stick with it

      Yeah, me too. I don't know why I suggested it. Another generic solution is to change the bottom tested loop into an infinite loop.
      do { ... next if ...; # XXX ... last if ...; # XXX ... } while cond();
      becomes
      for (;;) { # for ever ... next if ...; # OK ... last if ...; # OK ... last if !cond(); }