Uhm... some things to point out here
First, you don't use strict, and it hurts :-); it would have catched, for example:
%file2 = 'Source.txt' ;which is an error, twice. First, because you are using an hash instead of a variable; second, because you are assigning an odd number of elements to an hash
Second, you are slurping two files into memory, and that could be a pain if the files are too big, compared to your memory; probabily, you could do with reading one of the two line per line, and cache the other.
Third, you have three cycles, put probabily you could just grep; more on this later, because there is a badder thing before:
You open and close conversion.txt over and over: that is expensive! Why don't just open(APPEND, ">>conversion.txt") ; on top, close(APPEND); on bottom and print(APPEND "$line2") ; (watch the unbalanced parenthesis on that line!) when required?
You are comparing $line1 and $line2 with !=: that's a numerical comparison. If you want to do the same test on strings, you should use ne instead.
And now about the cycles: one way to compact them could be:
foreach my $line1 (@lines1) { print APPEND grep $line1 ne $_,@lines2 ; }
Take a look at the documentation (perldoc -f grep) to know more about grep
Apart of the errors, keep studying perl. Maybe your program is not that good still, but it seems to me you are headed in the right direction ;-)
Ciao!
--bronto
In reply to Re: Comparing 1 list and 1 array
by bronto
in thread Comparing 1 list and 1 array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |