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.
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.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/; } }
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
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. |
In Section
Seekers of Perl Wisdom