http://qs321.pair.com?node_id=24112


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.