If you have a flow control statement (next, last, return, exit, ...) at the end of an if block, you don't need to follow the block with an else block which saves a level of indentation for the following code. I tend to call the technique "early exit". Be warned however that some purists frown on the technique claiming that "things should only have one exit point". I use the technique a lot because I think it tends to clean up code something wonderful.

On a related note, if you change the sense of your if you don't need the next. For the resulting code see my earlier reply to the OP.

Note that you have duplicated the OP's error in using ne in place of ==. On a related note you shouldn't quote the 9 in the assignment to $planet_count - a count is generally a number not a string after all.

True laziness is hard work

In reply to Re^2: Help using a while loop with STDIN by GrandFather
in thread Help using a while loop with STDIN by amonline

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.