open my $fh, "test.txt" or die $!; foreach(<$fh>){ print "$.:$_"; }
In the above code I am reading each line from the file handle and printing both the content of each line and line number within the foreach loop, I am getting the file content correctly but I am getting the line number for each line as the last line number
Output :
4:First line 4:Second line 4:Third line 4:Fourth line
My file content is,
First line
Second line
Third line
Fourth line
In reply to Line number problem with foreach by vinoth.ree
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |