in reply to Question on Reading a file inside while and counting no.of lines
So your immediate problem would be solved by preincrementing instead of postincrementing, so that the incrementing happens before you print.
But your code could be simplified further by using $., documented in perlvar.
while( <FH> ) { print "$.:$_"; }
It starts at zero, so if you need it to start counting at some other base you'll have to add.
print $. + 1, ":$_";
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Question on Reading a file inside while and counting no.of lines
by Jim (Curate) on Jun 16, 2013 at 02:06 UTC | |
by davido (Cardinal) on Jun 16, 2013 at 06:50 UTC | |
by AnomalousMonk (Archbishop) on Jun 16, 2013 at 22:33 UTC | |
by Jim (Curate) on Jun 17, 2013 at 14:56 UTC |