Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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'

In reply to Re: remove backups by grinder
in thread remove backups by pfm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2022-12-02 13:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?