in reply to perl leaving out the last value?

Here's your problem:

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

The chomp function returns the number of characters chopped off the end of the line. chomp removes is a line break character. If you have no line break at the end of your text file, then chomp will not remove any characters, thus returns 0. So for the last line, you end up with:

while (0)

So the block does not get executed.

Try replacing constructions like this:

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

with this instead:

while (defined($symbol = <IN>)) { chomp($symbol);
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: perl leaving out the last value?
by Eliya (Vicar) on Apr 17, 2012 at 22:14 UTC
    while (defined($symbol = <IN>))

    With this particular construct, Perl automatically adds the defined(), so you can safely omit it if you prefer brevity.

    $ perl -MO=Deparse -e'while ($symbol = <IN>) { chomp($symbol) }' while (defined($symbol = <IN>)) { chomp $symbol; } -e syntax OK