in reply to Re: Compare script
in thread Compare script

I went through the code, making changes mostly for practice. It is *untested*. Hopefully the comments are of use. Furthermore, hopefully others can criticize me for my deficiencies:

#use strict; # don't disable strict. Period. # you are only using $comparetime within the compare() function # If you define it here, then it should be passed to the sub as # a parameter my $comparetime="0"; # sub compare; # no need for this my $Clinrxdir="D:\\StoreAccess\\shared\\sup shared\\"; opendir(DIR,$Clinrxdir); my @Files= readdir(DIR); closedir(DIR); for my $cpupdate (@Files){ if($cpupdate =~ m/\s*cp_/i){ my $m_time = (stat($Clinrxdir.$cpupdate))[9]; # what does a print() say about $m_time here? my ($i_wday, $i_month, $day, $year) = (localtime($m_time))[6,4 +,3,5]; # why are you breaking $m_time up. Depending on what you want to d +o, # it may be easiest to simply compare $m_time as an int my $comparison = compare($orig_mtime, $cmp_mtime $cupupdate); print "Timestamp for " . $cpupdate . " " . $m_time ."\n"; } } # I'm lost as to where $file comes from here... print "This is a test of file = " . $file . "\n"; print $file; system("pause"); sub compare(){ my ( $orig_mtime, $cmp_mtime, $cpuupdate ) = @_; if($cmp_mtime > $orig_mtime){ my $file = $cpupdate; } else{ #else{$comparetime=$string;} # it looks like you are trying to cause more than one side # effect with your subroutine, as opposed to focusing on providing # a single return. Personally, I've learned that mixing function # programming with global data will lead to bugs that are very # difficult to track down. # if you want to set $comparetime to $string, you should do it # outside of this routine, after you've collected up compare() # result } }

Steve