I want to compare 2 arrays (@DAT & @DIR - which represent an array of files in 2 different directories) and return an array of entries in @DAT that don't exist in @DIR and an array of entries in @DIR that don't exist in @DAT. I have written the following code which appears to work, however I'm new to PERL and like any hints/suggestions on how it might be improved - the array will arrays will be holding substantial amounts of data so performance is an issue:
my @DIR = ("one", "two", "three"
;
my @DAT = ("two", "three", "four"
;
for($cntDAT=0; $cntDAT < scalar(@DAT); $cntDAT++) {
for($cntDIR=0; $cntDIR < scalar(@DIR); $cntDIR++) {
if (@DIR[$cntDIR] eq @DAT[$cntDAT]) {
splice(@DIR, $cntDIR, 1);
$cntDIR = ($cntDIR - 1);
splice(@DAT, $cntDAT, 1);
$cntDAT = ($cntDAT - 1);
$cntDIR = 0;
last;
}
}
}
my @DIR = ("one", "two", "three"
my @DAT = ("two", "three", "four"
for($cntDAT=0; $cntDAT < scalar(@DAT); $cntDAT++) {
for($cntDIR=0; $cntDIR < scalar(@DIR); $cntDIR++) {
if (@DIR[$cntDIR] eq @DAT[$cntDAT]) {
splice(@DIR, $cntDIR, 1);
$cntDIR = ($cntDIR - 1);
splice(@DAT, $cntDAT, 1);
$cntDAT = ($cntDAT - 1);
$cntDIR = 0;
last;
}
}
}