in reply to Line number problem with foreach

Hi ree,

foreach:

First it will fetch all the data from the file and store it into the buffer, then from the buffer only it will print the data. So while storing the buffer it self line number($.) getting incremented. So finally it will have last line number only. So while printing it will print last line number.


Instead of foreach you can use while it will print correct line number.