in reply to improve performance

Update: Added simulation.

Update: Changed to ! exists ...

Looping and grep'ing for each temp file is likely expensive. This populates @newarray with new files only.

# this hash has list (keys) of all the files previously processed my %processed = map { $_ => 1 } @arraytocompare; my $path = "/tmp/testpatch"; opendir DIR, $path or die $!; # in this array i get all the new files which i need to process now my @newarray = map { ! exists $processed{$_} ? $_ : () } readdir DIR; closedir DIR;

The above is simulated below and outputs 8000 taking just a fraction of a second to complete.

# this hash has list (keys) of all the files previously processed my %processed = map { $_ => 1 } 100001 .. 108000; # in this array i get all the new files which i need to process now my @newarray = map { ! exists $processed{$_} ? $_ : () } 108001 .. 116 +000; print scalar @newarray, "\n";