Robert wrote: > When Perl is doing this comparison is it doing it line by line (like an > actual DIFF) or is it putting the lines into an "array" and the checking > that array against the second file? >
Well yes and no, to both. It is storing the lines temporarily, but it is storing them to a hash, not an array. Then it is checking them line by line. Depending on the purposes there are several large differences between the code and a "DIFF". For one, order is not maintained in a hash so it is really checking just to see if the line did exist in the first file, rather than that they are in the same order, which matters to a diff. Secondly it is checking to see if that line is in fact Perly true, so if a line consisted of just a 0 it would be false and return a false negative. Thirdly, because a hash can only store a key a single time then duplicated lines would be unconditionally kept, and no indication provided, even if for example the second file contained 43 copies of the same line and the first file only contained 1. There are other issues, for instance the first three opens check for success but the others don't. Additionally there is absolutely no reason to open/close the file within the loops, this really kills efficiency. If you are really looking for a diff creator there are several good ones on CPAN. http://danconia.org > use strict; > use warnings; > > open VASH, "vash.txt" or die "Can't open the file: $!\n"; > open MONH, "monh.txt" or die "Can't open the file: $!\n"; > open MANI, "mani.txt" or die "Can't open the file: $!\n"; > > my %dict; > > $dict{$_} = 1 while <VASH>; > > # This will insert in the text files the lines that are in > # the Vashon but not in the Monhegan > while (<MONH>) { > open VASH2MONH, ">>VASH2MONH.TXT"; > print VASH2MONH if !$dict{$_}; > close VASH2MONH; > } > print "Mohegan comparison is done.\n"; > > # This will insert in the text files the lines that are in > # the Vashon but not in the Manitou > while (<MANI>) { > open VASH2MANI, ">>VASH2MANI.TXT"; > print VASH2MANI if !$dict{$_}; > close VASH2MANI; > } > print "Manitou comparison is done.\n"; > > close MANI; > close MONH; > close VASH; > > print "Comparison is completed.\n"; > > It works. I am just wondering in what fashion it IS working. > > Robert > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>