in reply to Re^3: Re Execute Lines of Code ("loops")
in thread Re Execute Lines of Code
A bare block is, in Perl, a loop that falls through after its first pass. This is by language definition and so it should not be discounted in one's mental model of the language.
I think of a bare block primarily as a looping construct. If a block follows the normal pattern of a closure, I expect it to be just a scoping construct. I haven't found the worth of a bare block to put over or under a package:
and{ package Yme; code; }
package Ynot; { code; }
I am not enamoured of labels in Perl and tend to avoid them. Labels should be used only when necessary to choose a loop or to clarify a mess which cannot be cleaned up.
Labels smell. They all fall into one namespace, cannot be declared, and are slimey to name. Labels and goto behavior seem inadequately defined in the docs. Many people expect a goto LABEL to go to the textually nearest label, with more active use, this model breaks down because the actual behaviour is more dynamic.
Pop quiz:
In the below code, what is the output?
And again, with the marked lines uncommented?
sub lup { "LOOP" } sub say { print @_, $/; sleep 1; } LOOP: say 0; #sub mysub { # uncomment INNER: { say 1; goto +lup(); say 2; } LOOP: { say 3; goto LOOP; LOOP: say 2; } #} ### uncomment #mysub(); ### uncomment
Be well,
rir
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bare Blocks And Labels (Re^4: "loops")
by tye (Sage) on Jan 29, 2008 at 20:50 UTC | |
|
Re: Bare Blocks And Labels Was: Re^4: Re Execute Lines of Code ("loops")
by ysth (Canon) on Jan 30, 2008 at 09:18 UTC |