Actually, you don't have to parse the rest of the do block to figure out what is going on. Once you see ";\ndo {\n" you know (from the ";" and newlines) that it isn't a (sensible) conversion of a block to an expression and (from the "{") that it isn't "do file".

There was a smiley after the paragraph you quote. The point of that was to illustrate how hard the loop control shortcuts can be to parse. Your example was quite small so figuring out where each control change branched to was not difficult. I still prefer "do {" because it makes most people think "loop" much faster and because the branches stand out much more. Hiding a branch with something small that doesn't change indentation (like redo or goto) means that the structure of the code is not nearly as visually discernable.

So I avoid naked blocks, redo, next, and last because they are easy to abuse and require more visual energy to parse. That doesn't mean I never use them, of course (though I've never found a use for naked block as a loop). For example, redo, next, and last are important tools for allowing you to use Perl's most natural looping construct (for(@list)) in more situations rather than resorting to a more error-prone alternative.

As a few other examples of this have shown recently, pulling the "naked block plus redo" out for very simple problems can lead to producing much more complex code than is required because it doesn't put much pressure on you to figure out the structure of the code since they give you such abitrary control of the flow.

And it certainly isn't a tool I would ever suggest to a person already having problems writing fairly simple code in a well-structured manner.

        - tye (but my friends call me "Tye")

In reply to (tye)Re2: crafting a decent CLI by tye
in thread crafting a decent CLI by PetaMem

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.