in reply to Re: Bring out your Old Perl Code
in thread Bring out your Old Perl Code
I personally believe one may also play with some code from http://dev.perl.org/perl1/dist/example.gz (which I found mentioned in a recent post.) Actually it would be interesting to rewrite equivalent code in pre-5.10 Perl 5 code, in 5.10 if it has some advantage, and perhaps in Perl 6 if it is interesting. I'm skipping gsh and trying some of the shorter examples:
#!/bin/perl open(goners,"find . -mtime +14 -print|"); while (<goners>) { chop; unlink; }
Ah! Larry, Larry! You must be a n00b ;) Don't we suggest the use of File::Find and relatives all the time?
#!/usr/bin/perl use strict; use warnings; use File::Find; use 5.010; find { no_chdir => 1, wanted => sub { unlink if -f -M > 14 } }, '.'; __END__
(I don't think you want to unlink directories, anyway, don you?)
#!/bin/perl die "Usage: euthanasia directory days" unless $#ARGV == 1; ($dir, $days) = @ARGV; # assign array to list of variables die "Can't find directory $dir" unless chdir $dir; open(goners,"find . -mtime +$days -print|") || die "Can't run find +"; while (<goners>) { chop; unlink; }
#!/usr/bin/perl use strict; use warnings; use File::Find; use File::Basename; use 5.010; BEGIN { my $name = basename $0; sub USAGE () { "Usage: $name <directory> <days>\n" } } die USAGE unless @ARGV == 2; my ($dir, $days) = @ARGV; find { no_chdir => 1, wanted => sub { unlink if -f -M > $days } }, $dir; __END__
And now, I'm half way through working on scan_df but I must get out of my house in a few minutes, so I'll complete that later...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Bring out your Old Perl Code
by blazar (Canon) on Dec 29, 2007 at 22:17 UTC |