Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl use strict; use File::Find; my $mail_to = 'perlmonk@perlmonks.org'; my $subj = 'FTP report'; my $date = scalar localtime; my @deletions; # Let's define the paths. my $one_month = '/ftp'; my $one_week = '/ftp/ftp/incoming'; # Traverse desired filesystems my $days = 30; File::Find::find({wanted => \&wanted}, $one_month); my $days = 7; File::Find::find({wanted => \&wanted}, $one_week); # Send the report. open(MAIL, "|/usr/lib/sendmail -t ") || die "Can't open sendmail: $!"; print MAIL <<MESSAGE; From: perlmonk To: $mail_to Subject: $subj Weekly FTP policy report for $date ---------------------------- MESSAGE # What did we find? if ($#deletions == 0 ) { print MAIL "Nobody violated our FTP policy. No files deleted."; } else { print MAIL "The following files have been deleted:\n\n"; for my $element (@deletions) { print MAIL "$element\n"; } } close(MAIL); sub wanted { /software|patch|files/i and $File::Find::prune = 1; return if ((-d $_) || (int(-M $_) < $days)); push @deletions, "$File::Find::name"; unlink "$File::Find::name" || die "Can't delete file: $!"; }
Shouldn't unlink only delete the files that go into @deletions?
What am I missing?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Whoops! I deleted everything!
by tachyon (Chancellor) on Dec 10, 2002 at 22:57 UTC | |
by sauoq (Abbot) on Dec 11, 2002 at 00:50 UTC | |
by tachyon (Chancellor) on Dec 11, 2002 at 10:22 UTC | |
by Anonymous Monk on Dec 10, 2002 at 23:46 UTC | |
by submersible_toaster (Chaplain) on Dec 11, 2002 at 01:29 UTC | |
|
Re: Whoops! I deleted everything!
by sauoq (Abbot) on Dec 11, 2002 at 00:21 UTC | |
by Anonymous Monk on Dec 11, 2002 at 02:15 UTC | |
by sauoq (Abbot) on Dec 11, 2002 at 02:27 UTC | |
|
Re: Whoops! I deleted everything!
by jdporter (Paladin) on Dec 10, 2002 at 22:30 UTC |