mandog has asked for the wisdom of the Perl Monks concerning the following question:
What am I missing? I want to remove all the files on a volume that are older than 30 days. The first step is to find them. In sh I say:
find /backup -mtime +30
In perl I say:
#!/usr/bin/perl -w use strict; my $dir = $ARGV[0]; my $thirty_days_ago = time() - ( 30 * 24 * 60 * 60 * 60 ); my @files; use File::Find; find( \&wanted, $dir ); sub wanted { my @stats = (); # ignore symlinks if ( !-l $_ ) { @stats = stat($_) or warn "couldn't stat $_\n"; } # 9 is mtime; if ( !-l $_ && $stats[9] < $thirty_days_ago ) { push @files, "${File::Find::dir}/$_"; } } print join ( "\n", @files ), "\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (1) line of sh vs (~20) lines of perl ?
by broquaint (Abbot) on Nov 18, 2002 at 16:09 UTC | |
by Aristotle (Chancellor) on Nov 18, 2002 at 16:13 UTC | |
Re: (1) line of sh vs (~20) lines of perl ?
by VSarkiss (Monsignor) on Nov 18, 2002 at 16:07 UTC | |
Re: (1) line of sh vs (~20) lines of perl ?
by Thelonius (Priest) on Nov 18, 2002 at 16:12 UTC | |
(z) Re: (1) line of sh vs (~20) lines of perl ?
by zigdon (Deacon) on Nov 18, 2002 at 15:59 UTC | |
Re: (1) line of sh vs (~20) lines of perl ?
by perrin (Chancellor) on Nov 18, 2002 at 16:04 UTC | |
Re: (1) line of sh vs (~20) lines of perl ?
by waswas-fng (Curate) on Nov 18, 2002 at 17:22 UTC | |
More like 1 line of sh vs 1 line of perl
by buckaduck (Chaplain) on Nov 18, 2002 at 21:27 UTC | |
Re: (1) line of sh vs (~20) lines of perl ?
by grantm (Parson) on Nov 19, 2002 at 09:00 UTC |