user391986
user391986

Reputation: 30906

perl rmtree throwing empty exception

I'm having this very weird where i'm using rmtree("C:\myfolder"); and it's throwing some kind of exception but it is doing what it is supposed to.

I have this enclosed in

eval {
  rmtree("C:\myfolder");
};
if($@) {
   print $@;
}

If the folder exists I get an exception thrown eventhough the folder is succesfully deleted. The thrown exception is blank nothing at all. I even tried setting rmtree("C:\myfolder", {verbose => 1}) in rmtree but same thing.

My current hack is to do

eval {
   eval {
  rmtree("C:\myfolder");
  };
};
if($@) {
   print $@;
}

Upvotes: 0

Views: 483

Answers (2)

cirne100
cirne100

Reputation: 1558

How can you detect a blank exception??

From perldocs:

remove_tree( 'foo/bar', 'bar/rat', {error => \my $err} );
if (@$err) {
    for my $diag (@$err) {
        my ($file, $message) = %$diag;
        if ($file eq '') {
            print "general error: $message\n";
        }
        else {
            print "problem unlinking $file: $message\n";
        }
    }
}
else {
    print "No error encountered\n";
}

In Windows, I know that relative paths work with /. I think absolute paths work with / too!

remove_tree("C:/myfolder"); #this should work

Upvotes: 2

Leon
Leon

Reputation: 1141

try escaping the backslash ie.

"C:\\myfolder"

Upvotes: 2

Related Questions