You are quite correct.
My examples were quickly contrived with the focus on variable scoping of something in a while loop which has a logical conditional expression.

For a normal while (my $line = <$fh>){} loop, I would usually have something like "next if blank line" in the body of the loop. The idea expressed in the loop conditional being that all lines will be looked at.

For a command loop, one that is interactive with the user, I would express the idea that "this loop usually ends when the user types "quit" of some variant of that" within the while() statement. I would prefer that as opposed to "last if ...." within the body of the loop. I didn't frame examples in the context of a command loop from <STDIN> because testing such things takes a few extra steps in my dev environment. My code tends to have either a super fancy GUI or no UI at all, with the later case being far and away the most common. I tend to write "middleware" data processing or system code.


In reply to Re^7: First attempt at bringing in file for input/output by Marshall
in thread First attempt at bringing in file for input/output by catfish1116

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.