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...

--
If you can't understand the incipit, then please check the IPB Campaign.

In reply to Re^2: Bring out your Old Perl Code by blazar
in thread Bring out your Old Perl Code by Gavin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.