in reply to while 's 'continue' block

I use continue on a naked block when the code to get to the "next" item needs to be easily accessible:
{ blah blah; blah blah; last if $some_exit_condition; blah blah; blah blah; next if $some_early_next_condition; blah blah; blah blah; last; # or redo, if near-infinite loop } continue { blah blah; blah blah; redo; }
So here, the continue block contains the "get to the next item" code in a clean location. Leaving out that last "redo" means I could use it as a "finally" clause... no matter what exit I take via "next" inside the block, it's gonna run that code.

Sorry for the abstract code here. A real example is still gelling in my head. If pressed, I show it.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: while 's 'continue' block
by coreolyn (Parson) on Jan 04, 2001 at 21:44 UTC

    No need I see what your saying. This could clean up many little messy whiles that I construct. Thanks!

    coreolyn

Re: Re: while 's 'continue' block
by extremely (Priest) on Jan 05, 2001 at 01:15 UTC
    This isn't a USE but it is pretty cool (though it is semi-obfuscated):
    #!/usr/bin/perl -w use strict; my @a = ("\nr,kcelrPeH an AuJsthotre "); { my $a = pop @a; if ( 1 < length $a ) { push @a, substr($a,0,length($a)/2), scalar(reverse substr($a,length($a)/2)); next; } print $a; } continue { redo if @a; }

    I've occasionally used continue and the naked block trick to convert recursion into a stack queue sorta like above.

    --
    $you = new YOU;
    honk() if $you->love(perl)