Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: remove_tree dies even when trapped with eval

by choroba (Cardinal)
on Jun 12, 2015 at 15:30 UTC ( [id://1130211]=note: print w/replies, xml ) Need Help??


in reply to remove_tree dies even when trapped with eval

Does the script really die because of that? I ran the following in one terminal:
my $list = join ',', 'a' .. 'z'; mkdir '1'; open my $FH, '>', $_ for glob '1/' . ("{$list}" x 3);

And while it was running, I ran the following in the same directory in the second terminal:

use File::Path qw{ remove_tree }; print remove_tree('1'); print "FINISHED\n";

I got the error message you mentioned, but "FINISHED" was printed, too, so the program didn't die. The documentation is somehow unclear on this:

If make_path or remove_tree encounter an error, a diagnostic message will be printed to STDERR via carp (for non-fatal errors), or via croak (for fatal errors).
If you just want to avoid the message, you can use the documented error option:
use Data::Dumper; use File::Path qw{ remove_tree }; my $err; remove_tree('1', { error => \$err }); print Dumper($err);

Which returns:

$VAR1 = [ { '1' => 'cannot remove directory: Directory not empty' } ];
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2024-04-25 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found