This line (repeated twice with different identifiers):

while (chomp($symbol = <IN>))

... doesn't do what you want. chomp returns the total number of characters removed. Your last line has no line ending, so no characters are being removed. Since no characters are being removed, the return value of chomp, on the last iteration, is the moral equivelant of 'false'. Thus, the while() loop terminates without processing the last line.

Move the chomp inside the loop.

Additional reference on using the diamond operator: <>, truth and falsehood, and while loops. Also perfaq5. Three of those links provide examples of where to place the chomp.

Update: The documentation for chomp may actually contribute to confusion, since it shows both the correct placement within a while(){} loop, and also an example of how to chomp a single file-read outside of the context of a loop, in a way that would be inappropriate in a while loop.


Dave


In reply to Re: perl leaving out the last value? by davido
in thread perl leaving out the last value? by perllearner007

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.