'Current file line number with $. variable
I understand that I can get the current line number of a file I am looping through with the builtin variable $.. As an experiment, I used that to prefix each line in a file with the value of $. (the current line number). However, this did not work as expected. I.e., given the following file contents
line one
line two
line three
then I would expect the following code to prefix each line with its line number
for my $line (<FILE>) {
print "$. : $line";
}
but, instead, it gives the following output
3 line one
3 line two
3 line three
prefixing each line with the number of lines in the file. Instead of the current line.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
