lightoverhead has asked for the wisdom of the Perl Monks concerning the following question:
if I want to print the line number of a file I did this:
while(<>){ print "$.\n" }
it works fine. However, if I try to use "map":
map{print "$.\n"}<>;it can only print the last(or total) line number.
Does anyone know why this happens? How should I (or Can I)use "map" or "grep" to get or the line number of a file using "$."?
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Different behaviors between "while" and "map"
by friedo (Prior) on Dec 06, 2008 at 00:08 UTC | |
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 | |
|
Re: Different behaviors between "while" and "map"
by chromatic (Archbishop) on Dec 06, 2008 at 00:58 UTC | |
|
Re: Different behaviors between "while" and "map"
by JavaFan (Canon) on Dec 06, 2008 at 00:50 UTC |