in reply to in Perl find call looking to exclude folder and ignore duplicate finds.
Eliminating duplicates is not an easy problem, and I know of no portable solution. I believe ack does it by using the stat() built-in to get the inode number, which it uses as the key to a hash. Except under Windows, where it uses the absolute path name computed by Cwd::abs_path().
The untested Perl code to insert into the find() function would be something like
state $found = {}; my $key = $^O eq 'MSWin32' ? abs_path( $_ ) : do { my ( $dev, $ino ) = stat( $_ ); "$dev $ino"; }; return if $found->{$key}++;
Obviously if you need the Windows-specific code you will have to use Cwd 'abs_path'; somewhere.
But what I'm really hoping is that this post will trigger someone to point out some Perl module that encapsulates all this.
|
|---|