in reply to Wondering about File::Find

(Answer reposted here.)

Checking and setting a value in a hash has to be faster than hitting the filesystem. Here is a script that does this:

use strict; use File::Find; my %seen; sub wanted { if (-d $File::Find::name) { if ($seen{$File::Find::name}) { $File::Find::prune = 1; return; } $seen{$File::Find::name} = 1; } print "$File::Find::name\n" if /\.pm$/; } find \&wanted, @INC;
Note that the wanted function should check %seen only for actual directories. Setting $File::Find::prune is what actually stops File::Find from recursing further into the directory.