Ok below is the modified product. Thanks for the suggestions. The only other thing that I would like to add is the ability to change the way the logs are handled. I would love to be able to have this:

** $date_script_was_run ***
File foo has been deleted.
File bar has been deleted.
Dir foobar has been deleted.

** $an_earlier_date_script_was_run ***
File foo has been deleted.
File bar has been deleted.
Dir foobar has been deleted.

Could I just add another sub to handle this and call the sub within the logging statements? So how could I change this to reflect that?
} else { open(ERRLOG, ">>$errorlog") or warn "scrapping error output\n"; + eval { die "($!)"; }; if ($@) { print ERRLOG "Cannot delete dir $_ : $@!\n"; } }

Anyhow, here is what I have so far. If you can give me a tip on what to look through, or point me in the right direction that would be great.
#!/usr/bin/perl -w use strict; use File::stat; use File::Find qw(finddepth); my($create_date, $current_date, $time_month, $month_old); my($dir,$dirs,$logfile,$logfile2,$errorlog); $_ = *File::Find::name; $month_old = 2592000; $current_date = time; $dir = 'd:\data\Transfer'; $logfile = 'd:\data\log.txt'; $logfile2 = 'd:\data\log_keep.txt'; $errorlog = 'd:\data\errorlog.txt'; finddepth \&deletion, $dir; # # Start of my function 'deletion' # sub deletion { if (-f) { $create_date = stat($_)->ctime; if ($create_date < ($current_date - $month_old)) { if (unlink ($_)) { open(LOG, ">>$logfile") or warn "discarding logfile output +\n"; print LOG "FIle: $_ - has been deleted.\n"; close (LOG) or warn "Can't close $logfile: $!"; } else { open(ERRLOG, ">>$errorlog") or warn "scrapping error outpu +t\n"; eval { die "($!)"; }; if ($@) { print ERRLOG "Cannot delete file $_ : $@!\n"; } } } else { open(LOG, ">>$logfile2") or warn "discarding logfile output\n" +; print LOG "The file $_ is newer than 30 days.\n"; close(LOG) or warn "Can't close $logfile2: $!"; } } else { $create_date = stat($_)->ctime; if ($create_date < ($current_date - $month_old)) { if (rmdir ($_)) { open(LOG, ">>$logfile") or warn "discarding logfile output +\n"; print LOG "Directory: $_ - has been deleted.\n"; close (LOG) or warn "Can't close $logfile: $!"; } else { open(ERRLOG, ">>$errorlog") or warn "scrapping error outpu +t\n"; eval { die "($!)"; }; if ($@) { print ERRLOG "Cannot delete dir $_ : $@!\n"; } } } else { open(LOG, ">>$logfile2") or warn "discarding logfile outpu +t\n"; print LOG "The dir $_ is newer than 30 days.\n"; close(LOG) or warn "Can't close $logfile2: ($!)"; } } }

Thanks,
djw

In reply to Re: A couple of problems.... by djw
in thread A couple of problems.... by djw

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.