You should always use strict
and use warnings
at the start of all your programs and declare all variables at their point of first use. This applies especially when you are asking for help with your code.
Is all the data in your files numeric? If not then enabling warnings would have told you that that the <
and >
operators are for comparing numeric values rather than general strings.
Once a file has been read through completely - i.e. the second loop's while
condition terminates - you can read no more data from the file unless you open
it again or use seek
to rewind to the beginning.
In general it is better in these circumstances to read the smaller of the two files into an array and use the data from there. If both files are very large then something special must be done.
What sort of file comparison are you trying to do? Are you making sure that the two files are identical, or that all data in the second file appears in the first, or something else? Please give an example of your two data files so that we can help you better.