One way to make the eval/die a little more elegant is to use the
Error module and have 'real' exceptions:
#!/usr/bin/perl
use warnings;
use strict;
use Error qw/:try/;
use File::Find;
{
package Exception::FoundFile;
use base qw/Error/;
sub new {
my $s = bless {}, __PACKAGE__;
$s->{_file} = shift;
return $s;
}
sub file { return shift->{_file}; }
}
try {
find(sub {
my $file = $File::Find::name;
# Show our working, so you can see we stop early
print "Examining $file\n";
throw Exception::FoundFile->new($file)
if ($file =~ /f/); # Or whatever your condition is
},
".");
}
catch Exception::FoundFile with {
my $e = shift;
print "Found file: ", $e->file, "\n";
}
otherwise {
print "Didn't find a file\n";
};
But the 'real solution' would be for the File::Find interface to respect a return value from the sub as to whether it should continue or not.
Too late for that now, sadly.