Short version: I'm strictly following PBP on this one, and I agree with your current usage.

I'm following my own shortcut rule to this: Always use labels after next, redo, and last.. That includes: Use labels even if the loop isn't nested. Maybe it will become nested when some other guy adds some feature years later, and for that case the label adds robustness. When refactoring complex loops it helps to define the scope: Extracting an inner loop into a subroutine needs extra care if the inner loop contains a last OUTER;.

It has already been noted by others that good names for labels also make good documentation - next FILE; or last TRY; tell pretty well what the line is trying to achieve, and I don't need to scroll even if that line happens to be at the top of my screen.

I don't see these loop controls related to goto, but rather to two other mechanisms of execution control: return and die. A return is implicitly labeled with the surrounding sub (I know, special cases exist where it isn't), and die is followed by a description why you bail out. With a label, loop control keywords achieve the same level of self-explanation. Loop control, returning from a subroutine and exceptions are part of every modern programming language, and they have in common that they go strictly "upward" in the call stack or loop hierarchy. A goto LABEL; or even, horrors, goto EXPRESSION is indeed scary, not only for maintenance of the code, but also for those who write compilers and interpreters.


In reply to Re: Perl Best Practices - Loop Labels by haj
in thread Perl Best Practices - Loop Labels by kcott

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.