Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: remove backups

by grinder (Bishop)
on Nov 05, 2002 at 11:57 UTC ( #210433=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://210433]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-12-08 19:35 GMT
Find Nodes?
    Voting Booth?

    No recent polls found