Hey sorry i got busy with other tasks, only just had a chance to get back on this. So I tried the grep suggestion but i had a problem with the count of files in the directory being 2 more than were actually there, even when its empty? I wasn't sure why this would happen, there are no hidden or system files or sub directries in this windows directory. So I tried another approach, as you can see below. Will grep save time and how can I manage the output to ignore the 2 'ghost' items its counting?

Also I had to add in a bit to check for .lock files that are created when import jobs start, I was wondering if this can be consened also? I'm curious if anyone has some reading that pertains to what types of things can be run in the same "query" for lack of a better term, cause I end up doing things seperately for each occourance I need for lack of understanding.

# Looks in $dir and sets $latest->{file} with newest file and sets $ol +dest->{file} with oldest file. my ( $latest, $oldest ) = ( sort { $a->{ mtime } <=> $b->{ mtime } } map { { mtime => -M $_, file => $_ } } <$dir/*> )[ 0, -1 ]; my ( $newM, $oldM ) = map +( stat )[ 9 ], $latest->{ file }, $oldest-> +{ file }; # Looks in $dirL and sets $latestL->{file} with newest file and sets $ +oldestL->{file} with oldest file. my ( $latestL, $oldestL ) = ( sort { $a->{ mtime } <=> $b->{ mtime } } map { { mtime => -M $_, file => $_ } } <$dirL/*> )[ 0, -1 ]; my ( $newML, $oldML ) = map +( stat )[ 9 ], $latestL->{ file }, $oldes +tL->{ file }; # Opens $dir and counts number of files my @files = <$dir/*>; my $fCount = @files; # Opens $dirL and counts, large files are processed seperately thus $d +irL my @filesL = <$dirL/*>; my $fCountL = @filesL; # Changes Newest/Oldest file display in email based on if any files ar +e found. if (defined($latest->{file})){ $latestF = 'Newest File: '. $latest->{file}. ' with a timestamp of + '. scalar localtime $newM; $oldestF = 'Oldest File: '. $oldest->{file}. ' with a timestamp of + '. scalar localtime $oldM; } # Changes Newest/Oldest file display in email based on if any large fi +les are found. if (defined($latestL->{file})){ $latestFL = 'Newest File: '. $latestL->{file}. ' with a timestamp +of '. scalar localtime $newML; $oldestFL = 'Oldest File: '. $oldestL->{file}. ' with a timestamp +of '. scalar localtime $oldML; } # Looking for the lock files generated when pLock(job1) job starts to +see when import started. my $pLock ='\\\\server\\E$\\directory1\\job1.lock'; my $pLockStat='No lock file for Job1 was found, this import is not cur +rently running.'; if ( -f $pLock ) { my @time = timeconv( -M $pLock ); my $pLockWhen=$time[1].' hours, '.$time[2].' minutes, and '.$ +time[3].' seconds ago'; $pLockStat='Lock file found for Job2, this import was started + '. $pLockWhen; } # Looking for the lock files generated when eLock(job2) job starts to +see when import started. my $eLock ='\\\\server\\E$\\directory1\\job1.lock'; my $eLockStat='No lock file for Job2 was found, this import is not cur +rently running.'; if ( -f $eLock ) { my @time2 = timeconv( -M $eLock ); my $eLockWhen=$time2[1].' hours, '.$time2[2].' minutes, and ' +.$time2[3].' seconds ago'; $eLockStat='Lock file found for Job2, this import was started + '. $eLockWhen; }

In reply to Re^2: Looking for some assistance in cleaning up a perl script by shadowfox
in thread Looking for some assistance in cleaning up a perl script by shadowfox

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.