in reply to del files that is 7 days or older

This might be sacrilege, but this really isn't something suitable for Perl. Or, should I say, there is a better solution (since it appears you are using *Nix):
#!/bin/sh /usr/bin/find /home/archive/logs/old -type f -mtime +7 -exec rm -fv {} + \;
just the sort of thing find was made for.

Replies are listed 'Best First'.
Re: Re: del files that is 7 days or older
by merlyn (Sage) on Feb 15, 2001 at 01:14 UTC
    Then simply turn it into a Perl program!
    $ find2perl /home/archive/logs/old -type f -mtime +7 -exec rm -fv {} \ +; >myprog $ chmod +x myprog $ ./myprog
    Of course, you can tweak it to use fewer resources with
    $ find2perl /home/archive/logs/old -type f -mtime +7 -eval unlink >myf +asterprog

    -- Randal L. Schwartz, Perl hacker

      On my Linux 2.2 box, find2perl much less efficient than find itself
      nicholas@neko/3:(pts-0.neko) ~/noding > /usr/bin/time x 0.10user 0.03system 0:00.15elapsed 85%CPU (0avgtext+0avgdata 0maxresid +ent)k 0inputs+0outputs (356major+205minor)pagefaults 0swaps nicholas@neko/3:(pts-0.neko) ~/noding > /usr/bin/time find /usr0/Downl +oads -type f -mtime +180 -exec rm -fv {} \; 0.00user 0.00system 0:00.01elapsed 0%CPU (0avgtext+0avgdata 0maxreside +nt)k 0inputs+0outputs (96major+15minor)pagefaults 0swaps
      (obviously "x" is the output from find2perl). The exact same set of examples, when run on Solaris 2.6 on an Ultrasparc produces similiar results.