Kris0r has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
Long story short I'm trying to compare two HTML files for differences. I already have a program that strips the HTML and puts each word on its own line, I'm happy with this. The output is two new files that I then want to compare differences between.
I now want a second program that does the comparing. I go ahead and open both files and save them to a new array:
open FILE1, $ARGV[0] or die "Couldn't open file: $!"; my @lines1 = <FILE1>; close(FILE1);
Same for a second file. I then try to compare them line-by-line using a foreach loop on the first same file. The exact code I use for the comparison is if($lines1[$_] eq $lines2[$_]). However I get the error:
Argument "line example here" isn't numeric in array element at compare.pl line 14.This confuses me, because I can access them exactly the same way outside the array, $lines[0] etc. Is there something obvious I'm missing? I'm fairly new to Perl so always happy to learn some theory behind the code. Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File to array and reading back
by roboticus (Chancellor) on Jun 19, 2012 at 10:26 UTC | |
by Kris0r (Initiate) on Jun 19, 2012 at 10:36 UTC | |
|
Re: File to array and reading back
by ww (Archbishop) on Jun 19, 2012 at 11:39 UTC | |
by choroba (Cardinal) on Jun 19, 2012 at 14:38 UTC | |
|
Re: File to array and reading back
by RichardK (Parson) on Jun 19, 2012 at 11:02 UTC |