| | |
comparision of two files
![]() |
•
•
Join Date: Sep 2006
Posts: 3
Reputation:
Solved Threads: 0
Hi Friends,
I am writing a script to compare two files put in two arrays and I expect the those elements which are found in array2 that are not in array1. here there are 2 files Perf.txt which contains some names, and Neu.txt contains some names which are common as well as some different names. Now I am interested only in different names that are not present in Perf.txt
My script:
open (PERF, "Perf.txt");
open (DSA, "Neu.txt");
@Perf = <PERF>;
@Neu = <DSA>;
my %seen; # lookup table
# build lookup table
@seen{@Neu} = ();
foreach $item (@Perf)
{
# print ($item) unless exists $seen{$item};
push (@miss, $item) unless exists $seen{$item};
}
foreach(@miss)
{
print "\nElement found ---> $_";
}
When I execute this I am getting all the names which are present in Neu.txt.
Please suggest me what I am wrong.
Thanks and Regards,
Raghavendra S
I am writing a script to compare two files put in two arrays and I expect the those elements which are found in array2 that are not in array1. here there are 2 files Perf.txt which contains some names, and Neu.txt contains some names which are common as well as some different names. Now I am interested only in different names that are not present in Perf.txt
My script:
open (PERF, "Perf.txt");
open (DSA, "Neu.txt");
@Perf = <PERF>;
@Neu = <DSA>;
my %seen; # lookup table
# build lookup table
@seen{@Neu} = ();
foreach $item (@Perf)
{
# print ($item) unless exists $seen{$item};
push (@miss, $item) unless exists $seen{$item};
}
foreach(@miss)
{
print "\nElement found ---> $_";
}
When I execute this I am getting all the names which are present in Neu.txt.
Please suggest me what I am wrong.
Thanks and Regards,
Raghavendra S
open (PERF, "Perf.txt") or die "can't open perf.txt: $!";
open (DSA, "Neu.txt") or die "Can't open neu.txt: $!";
chomp(@Perf = <PERF>);
chomp(@Neu = <DSA>);
my %seen; # lookup table
# build lookup table
@seen{@Neu} = ();
foreach $item (@Perf)
{
# print ($item) unless exists $seen{$item};
push (@miss, $item) unless exists $seen{$item};
}
foreach(@miss)
{
print "\nElement found ---> $_";
}•
•
Join Date: Apr 2007
Posts: 1
Reputation:
Solved Threads: 0
#!/usr/bin/perl:mrgreen:
use Algorithm:
iff qw(diff);
bag("Usage: $0 oldfile newfile") unless @ARGV == 2;
my ($file1, $file2) = @ARGV;
# -f $file1 or bag("$file1: not a regular file");
# -f $file2 or bag("$file2: not a regular file");
-T $file1 or bag("$file1: binary");
-T $file2 or bag("$file2: binary");
open (F1, $file1) or bag("Couldn't open $file1: $!");
open (F2, $file2) or bag("Couldn't open $file2: $!");
chomp(@f1 = <F1>);
close F1;
chomp(@f2 = <F2>);
close F2;
$diffs = diff(\@f1, \@f2);
exit 0 unless @$diffs;
foreach $chunk (@$diffs) {
foreach $line (@$chunk) {
my ($sign, $lineno, $text) = @$line;
printf "%4d$sign %s\n", $lineno+1, $text;
}
print "--------\n";
}
exit 1;
sub bag {
my $msg = shift;
$msg .= "\n";
warn $msg;
exit 2;
}
use Algorithm:
iff qw(diff);bag("Usage: $0 oldfile newfile") unless @ARGV == 2;
my ($file1, $file2) = @ARGV;
# -f $file1 or bag("$file1: not a regular file");
# -f $file2 or bag("$file2: not a regular file");
-T $file1 or bag("$file1: binary");
-T $file2 or bag("$file2: binary");
open (F1, $file1) or bag("Couldn't open $file1: $!");
open (F2, $file2) or bag("Couldn't open $file2: $!");
chomp(@f1 = <F1>);
close F1;
chomp(@f2 = <F2>);
close F2;
$diffs = diff(\@f1, \@f2);
exit 0 unless @$diffs;
foreach $chunk (@$diffs) {
foreach $line (@$chunk) {
my ($sign, $lineno, $text) = @$line;
printf "%4d$sign %s\n", $lineno+1, $text;
}
print "--------\n";
}
exit 1;
sub bag {
my $msg = shift;
$msg .= "\n";
warn $msg;
exit 2;
}
![]() |
Similar Threads
- hjsplit doenst work for avi files? (Windows NT / 2000 / XP)
- "Save Target As.." isn't working in IE6 (Web Browsers)
- Does Samba send deleted files to a recycle bin? (*nix Software)
- Dia, .PDB files (C++)
- Cannot transfer files from one hardrive to another =[ please help (Windows NT / 2000 / XP)
- FTP files (Geeks' Lounge)
Other Threads in the Perl Forum
- Previous Thread: Need help for conveting Perl Code to a C Code
- Next Thread: hi i have prob solve it plz
| Thread Tools | Search this Thread |





