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


In reply to Re^2: Compare script by stevieb
in thread Compare script by TheRedcoat

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.