in reply to Re: Compare script
in thread Compare script
#use strict; my $comparetime="0"; sub compare; ##defines locations to look for files $Clinrxdir="D:\\StoreAccess\\shared\\sup shared\\"; ##reads DIR opendir(DIR,$Clinrxdir); @Files= readdir(DIR); closedir(DIR); #for every file retured do the following foreach $cpupdate (@Files){ ##if the file starts with CP_ checks it's timestamp if($cpupdate =~ m/\s*cp_/i){ ##I did not write this section I was using code I read up on using goo +gle and found in other various ##scripts we used, for me the fact it broke it down in to a simple int + style var made life easier. my $m_time = (stat($Clinrxdir.$cpupdate))[9]; my ($i_wday, $i_month, $day, $year) = (localtime($m_time))[6,4,3,5]; ##prints what files where found and time stamps print "Timestamp for " . $cpupdate . " " . $m_time ."\n"; ##Attempting to use this sup to compare time stamps and change the $fi +le var to the one with most recent ##stamp compare($m_time); } } ##$file is pulled from the compare sub print "The oldest file= " . $file . "\n"; print "The time stamp for this file is " . $oldcomp . "\n"; system("pause"); ##this was meant to work in the following manner: look at time stamp. +if it's older than the one ##currently stored do nothing, if it's newer change $file to be the fi +le name of the newer file. ##this is where I realised my folly thanks to graff's code.. I was not + keeping anything to compare to ##other than the new string sub compare($){ local( $string ) = shift; if($comparetime > $oldcomp){ $file=$cpupdate; $oldcomp=$string;} else{$comparetime = $string;} }
|
|---|