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


in reply to deleting a file in perl

Something like this using File::Find, which IMHO is an overkill for what you need,
since you are just going through one directory, you could consider using opendir, if you want.

use warnings; use strict; use File::Find qw(find); die "No directory is specified" unless defined $ARGV[0]; my $dir = $ARGV[0]; find( \&unwanted, $dir ); sub unwanted { if (/^\.{1,}/) { return } else { print "Do you want to delete ", $_, $/; chomp( my $ans = <STDIN> ); unlink $_ if $ans =~ /\by\b/; } }
NOTE: Deleting a file could be both dangerous and so painful if in error, a wrong file is deleted, hence the need to check the file before deleting.
Hope this helps.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.