Thank you for your fast and detailed reply.
Larry Wall skribis 2005-01-29 11:08 (-0800):
> On Sat, Jan 29, 2005 at 05:59:40PM +0100, Juerd wrote:
> : Can last/redo be used outside loops? (i.e. with if or given)
> No, though of course what "loop" means is negotiable. Effectively,
> anything that captures the appropriate control exceptions is a loop.
redo could be useful in subs or even file scope.
CATCH { when Fatal { reset; redo; } }
And in given, for those who don't like fall-through:
GIVEN: given $foo {
when /^0x/ { $_.=hex; redo GIVEN; }
...
}
# Heh, I guess here $_.=hex, $_=hex and $_=.hex all do the same
# thing :)
> So there's some argument for keeping bare {...} as a do-once loop.
> (..) But this morning it occurs
> to me that if we defined C<do {...}> to be a do-once loop, it kind of
> naturally rules out putting an C<until> or C<while> modifier on it,
> since you then have conflicting loop specifications.
It also kind of naturally rules out that do { } is for grouping
statements in an expression, because it'd behave *very* differently in
void context. And wasn't Perl 6 supposed to weed out weird exceptions? :)
$foo = %*ENV<FOO>;
$foo = do { print "Foo: "; readline } until $foo.validate; # valid
do { print "Foo: "; $foo = readline } until $foo.validate; # invalid?
Maybe it doesn't hurt to tell people who need a once-loop to just use
loop with last:
loop {
...
last;
}
Those who find comfort in knowing beforehand that it'll only run once,
can use NEXT { last } :)
Juerd