Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

RE: Code for DELETING NT FILES

by autark (Friar)
on Jul 24, 2000 at 20:43 UTC ( #24112=note: print w/replies, xml ) Need Help??


in reply to Code for DELETING NT FILES

Well, as far as I can tell, you ask the user about the file _outside_ of the while-loop, and you don't take into consideration that $dir might be something else than '.'
This is how I would have written it (more or less):
my $dir = shift || '.'; opendir DIR, $dir or die "Can't open directory $dir: $!\n"; while (defined (my $file = readdir DIR) ) { next if $file !~ /^\w{10,}\d{4,}\.\d{1,}/; print "Found a file: $file\n"; print "are you sure that you want to delete $file 'Y/y(es)' " +; chomp( my $answer=<STDIN> ); do { unlink "$dir/$file" or die "Can't delete $file: $!\n" } if $answer =~ m%^Y(es)?$%i; }
You might have to use the 'while( defined (...) )'-construct if you are using an older perl.

Autark.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2020-11-30 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?