Possible Duplicate:
Comparing Two Arrays Using Perl
I am trying to find elements that are common in both the files:
below is my code. Please tell me what mistake I am doing.
open IN, "New_CLDB.txt" or die "couldn't locate input file";
open IN1, "New_adherent.txt" or die "couldn't locate input file";
use Data::Dumper;
@array = ();
while (<IN>) {
$line = $_;
chomp $line;
$a[$i] = $line;
++$i;
}
while (<IN1>) {
$line1 = $_;
chomp $line1;
$b[$m] = $line1;
++$m;
}
for ( $k = 0; $k < $i; ++$k ) {
for ( $f = 0; $f < $m; ++$f ) {
if ( $a[$k] ne $b[$f] ) {
push( @array, $a[$k] );
}
}
}
print @array, "\n";
There are several things one should improve:
use strict;anduse warnings;openpush @array, $value;And for SO questions … what exactly is your problem and what do you expect.