in reply to Re: Looking for some assistance in cleaning up a perl script
in thread Looking for some assistance in cleaning up a perl script
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; }
|
|---|