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


in reply to A warning about passing mountpoints as arguments to directory recursion programmes

Maybe it's just that I'm tired, but I don't see how this code is supposed to work. I have multiple problems.

Firstly, the recursivelyunlinkfiles function tries to call itself multiple times, but doesn't have an argument that's changed for the inner calls. What's the point of the recursion then?

Secondly, you're calling unlink without an argument so it defaults to unlinking $_, but I don't see where you're setting $_.

Thirdly, you don't filter out . and .. from the files readdir returns. If you actually recursed on the directory tree, this would lead to either a quick infinite loop, or a dangerous code that traversed the entire file system.

PS. if you just want a recursive deletion function, then take a look at File::Path or File::Path::Simple.