in reply to Different behaviors between "while" and "map"
The reason this happens is because the while loop is designed to operate on <> like an iterator. Thus, it reads one line at a time until it can't read anymore.
By contrast, using <> as the list for your map block reads the entire file in all at once, incrementing $. along the way. The entire file then gets passed to your map block as one big list, and by this time, $. has already been incremented to the number of the last line, so the same $. gets printed each time through the map block.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Different behaviors between "while" and "map"
by Joost (Canon) on Dec 06, 2008 at 00:43 UTC | |
by betterworld (Curate) on Dec 06, 2008 at 01:42 UTC | |
by JavaFan (Canon) on Dec 06, 2008 at 02:18 UTC | |
by ikegami (Patriarch) on Dec 06, 2008 at 06:09 UTC |
In Section
Seekers of Perl Wisdom