I agree with the view that next, last, and redo can make code less readable.

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:

{ package Yme; code; }
and
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


In reply to Bare Blocks And Labels Was: Re^4: Re Execute Lines of Code ("loops") by rir
in thread Re Execute Lines of Code by btobin0

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.