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


in reply to remove backups

Your script seems to be half way between being able to remove backup files from the current directory or an explicit directory (maybe passed in from the command line).

Here's how I would remove backup files from the current directory, without relying on external programs.

#! /usr/bin/perl -w use strict; use Getopt::Long; my $verbose_mode = ''; GetOptions('verbose' => \$verbose_mode); my $counter = 0; opendir DIR, '.' or die "Cannot open . for directory input: $!\n"; while( defined( my $entry = readdir(DIR) )) { next unless $entry =~ /~$/; if( unlink $_ ) { ++$counter; print "\t$_ deleted.\n" if $verbose_mode; } else { warn "Could not unlink $_: $!\n"; } } closedir DIR; print "I have deleted $counter backup files in current directory.\n"

I'll leave it as an exercise to the reader to figure out how to extend this to work on any directory. Disclaimer: I have only checked that this code is syntactically correct. It may not be semantically correct.


print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

Replies are listed 'Best First'.
Re: Re: remove backups
by pfm (Scribe) on Nov 05, 2002 at 16:06 UTC
    Just regards
    pfm="";