#!/usr/bin/perl
use Fcntl qw(:DEFAULT :flock);
use strict;

my $file_one    =       'file1.txt';
my $file_two    =       'file2.txt';


my %file_one_data       =       ();
my %file_two_data       =       ();


sysopen(FILE, $file_one, O_RDONLY);
flock(FILE, LOCK_SH);
                while(<FILE>) {
                        chomp;
                        $file_one_data{$_}      =       $_;
                }
flock(FILE, LOCK_UN);
close(FILE);

sysopen(FILE, $file_two, O_RDONLY);
flock(FILE, LOCK_SH);
                while(<FILE>) {
                        chomp;
                        $file_two_data{$_}      =       $_;
                }
flock(FILE, LOCK_UN);
close(FILE);

foreach (keys %file_one_data) {
        if(exists $file_two_data{$_}) {
                print "$_ exists in $file_one and $file_two\n";
        }
}


###############################
# Yupapa Web Hosting =^.^=
# Web Site - http://www.yupapa.com
# Email - [EMAIL PROTECTED]
###############################
"Sara" <[EMAIL PROTECTED]>
???????:[EMAIL PROTECTED]
######################

open (DATA, "data.txt") || die "Cannot open file. Reason: $!";
@data = <DATA>;
close(DATA);

open (LIST, "list.txt") || die "Cannot open list.txt. Reason: $!";
while (<LIST>) {
$found = 0;

foreach $line (@data) {
chomp $line;
if ($line eq $_) { $found = 1; last; }
$found = 0;
}

if ($found) {
print "Entry \"$_\" was found in data.txt <BR>";
}
else
{
print "Entry \"$_\" was NOT found in data.txt <BR>";
}
}

#####################

list.txt (contains 3 enteries)
######
file1.html
file3.html
file2.html
######

data.txt (contains 2 enteries)
######
file3.html
file1.html
######


The script is generating the following output

Entry "file1.html " was NOT found in data.txt
Entry "file3.html " was NOT found in data.txt
Entry "file2.html " was NOT found in data.txt

though, file1.html and file2.html exists in data.txt

Any ideas what I m doing wrong?

I want to compare both text files and the script should produce that this.
i.e after comparing the file nos. it should report which file is found and
which is not found.

file1.html was found in the data.txt
file2.html was NOT found in the data.txt
file3.html was foundi in the data.txt

TIA,

Sara.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to