Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: aborting File::Find::find

by jbert (Priest)
on Nov 17, 2006 at 10:14 UTC ( [id://584693]=note: print w/replies, xml ) Need Help??


in reply to Re^2: aborting File::Find::find
in thread aborting File::Find::find

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://584693]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-03-28 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found