in reply to Re: Hard disc pruner
in thread Hard disc pruner

Danger, Will Robinson, Danger! I really hope there are no directory names in that list of yours. Unlinking directories is usually a very bad idea - problems that even fsck has a hard time fixing can result.

Having said that and realizing the caffiene/sleep ratio is far too high, lets have some fun. Can we do this in one line? Why, yes!

@dead = grep { ! defined( $keep{$_} ) && ( -d $file ? rmdir : unlink ) && $_ } @files;
which will not call unlink on directories and return a list of the files deleted. It does assume that you have done a depth-first walk to generate the file names though. Now, this is useful, but I could generate the "expected to be blown away" list easier. What I would be interested in is the files that didn't get blown away.
@dead = grep { ! defined( $keep{$_} ) && ( ( -d $file ? rmdir : unlink ) || $_ ) } @files;
Well this is cute, but why couldn't we blow the file away?
@dead = grep { ! defined( $keep{$_} ) && ( ( -d $file ? rmdir : unlink ) || "$_:$!" ) } @files;
On second thought, follow lhoward's suggestion - this code is dangerous and will likely get you cursed by anybody having to maintain it.

Mik Firestone ( perlus bigotus maximus )