in reply to Re: Need help deleting *.bak files
in thread Need help deleting *.bak files

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);

Replies are listed 'Best First'.
Re^3: Need help deleting *.bak files
by Anonymous Monk on Jan 19, 2010 at 05:02 UTC
    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.

        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.

        Saying it twice doesn't make it true. The output on failure would be "filename: failure ($!)"