Think about Loose Coupling | |
PerlMonks |
Re^3: difference between two filesby roboticus (Chancellor) |
on Dec 19, 2013 at 11:15 UTC ( [id://1067810]=note: print w/replies, xml ) | Need Help?? |
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:
When you do so, your output is:
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:
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 Section
Seekers of Perl Wisdom
|
|