http://www.perlmonks.org?node_id=584548

marvell has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to abort a File::Find::find command from within the wanted subroutine. I'm attempting to find files with the same inode, but I can happily stop when I've found as many links as the link count of the target file

This is my hideous solution:

#!/usr/bin/perl use File::Find; my ($dir,$file) = @ARGV; # TODO usage, file and directory check my ($finode,$fnlinks) = (lstat($file))[1,3]; # TODO check for link count of 1 my @files; find(sub { return if $fnlinks == 0; # this is rubbish my ($inode,$nlink) = (lstat($_))[1,3]; return unless $inode == $finode; push(@files, $File::Find::name); $fnlinks--; }, $dir); print map {"$_\n"} @files;

--
Steve Marvell