> for practice I tried to run your script, but i doesn't work for me it 
> return an empty line but i pretty sure there's a difference between my
> two text files.

Hello.It's a simple comparing from the first file to the second file.
Given two example files here and run the script to get the results:

$ cat 1.txt 
abc123
123abc
dfdsfdsfsfddff

$ cat 2.txt 
123abc
abc123
dfjasidjfdijfdijfdijfidjfdijfi
fdifjfdifj

$ cat diff.pl 
use strict;

open TXT1, "1.txt" or die "$!";
open TXT2, "2.txt" or die "$!";
my %diff;

# I suppose you would compare the first file to the second file,then I
read the second file's contents to a hash.In this hash,each line in the
file is used as a key.As you know,hash keys are always uniq.For the hash
value,it's not important here,so set to '1'.
$diff{$_}=1 while (<TXT2>);

# Now I open the first file,and read each line in this file,and if this
line is the key of the hash above,then it means both 1st file and 2st
file have the same line.Otherwise,if this line is not the key of that
hash,it means this line is in 1st file but not in 2st file,it's printed.
while(<TXT1>){
 print unless $diff{$_};
}

close TXT2;
close TXT1;

# run the script
$ perl diff.pl 
dfdsfdsfsfddff


As I have said,the above script is a simple comparing.You maybe would
access CPAN for more other useful comparing.



> also i have question in these line of your code, i appreciate if you can 
> explain what it means.
> 
> $diff{$_} = 1; #does it mean to create an array whose key are the value
> of 
> $_ and values is always set to 1?
> print unless $diff{$_} = print the line, unless ????
> 
> newbie, here please bear.
> 
> thanks.
> 
> 
-- 
  Jeff Peng
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - IMAP accessible web-mail


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to