in reply to Need help deleting *.bak files

A simpler use of find is in order:
find(sub{ print("$File::Find::name: ", unlink() ? "success" : "failure ($!)" ) if /\.bak\z/; }, $searchdir);

Replies are listed 'Best First'.
Re^2: Need help deleting *.bak files
by ikegami (Patriarch) on Jan 19, 2010 at 00:38 UTC
    It's traditional to only be silent on success, and display errors on STDERR. It would also be useful to say what failed.
    find(sub{ if (/\.bak\z/ && -f) { unlink() or warn("Can't delete $File::Find::name: $!\n"); } }, $dir);
      Personally, I'd print everything, save to a file, and grep for errors; assuming this is a "manual" deletion, not part of a bigger project.

        You might have had an case if this code was part of larger project, but you're saying you assumed it wasn't?

        If it's not part of a bigger project, then it's a command line tool. Mixing everything together like that makes for a very bad command line tool. It makes it harder to use, and that's not even counting the difficulty in grepping the format you used.

        You also removed the code that makes it useful outside a big project: the reporting of whether an error occurred or not via the exit code.

        Finally, convention and tradition is being ignored without justification. Doing something different without reason is poor programming.