When you have a problem like this, you should add some print statements to show your variables, so you can verify that they hold what you're expecting. In this case, try adding $. to your existing print statement, like this:
print "$., $line"
When you do so, your output is:
10 15: 1 15: hw 15: r 15: u 15: hi 15: 2 15: hw 15: r 15: u 15: hi 15: 3 15: hw 15: r 15: u
So you can see that the line number is 15 for every iteration through your for loop. Why is that? It turns out that when you use foreach it wants a list in the parenthesis, so it reads the entire file at once. It then gives you one line at a time.
Generally when processing a file and want to do it one line at a time, we do it like:
while (my $line = <MYFILE>) { ... code in loop ... }
There are some other issues in your code, but I'll let your instructor clarify that.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re^3: difference between two files
by roboticus
in thread difference between two files
by varalaxmibbnl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |