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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl leaving out the last value?
by Eliya (Vicar) on Apr 17, 2012 at 22:14 UTC |