My solution (note probably not brilliant, but lots shorter and works :):
sub LastDalLoad { my $ContentsLoadMsg = shift; # setting log/sdf_misloader1.log may fail if SDF_LOGDIR is set ? $logFile = !$MISValue{ MIS_DBTYPE } || $MISValue{ MIS_DBTYPE } eq + 'db2' ? $logFile = "$ENV{ MIS_ROOT }/log/loadmsg_1.log" : $logFile = "$ENV{ MIS_ROOT }/log/sdf_misloader1.log"; my @Result; my $Command; my $indLines; my $finishedLine; my $beginningLine; my $found; my @beginningTime; my @finishedTime; my $maxSecondsAnHour; my @datePart; my @checkDate; my @checkTime; my $beginningInSeconds; my $finishedInSeconds; my $actualInSeconds; my $timeDiff; my $startDiff; my $status = $TRUE; # # Check the existance of the logfile # if( ( $statusLoadmsg = &FileExists( $logFile ) ) == $FALSE ) { &ResCode("WARNING"); &BrowseCode("File \"$logFile\" not found"); 
 &SummaryCode("WARNING"); return $WARNING; } # # read whole log file # if( &readFileContents( $logFile, $ContentsLoadMsg ) == $FALSE ) { &ResCode("E_LOADMSG_ERROR"); &BrowseCode("Could not open \"$logFile\""); 
 &SummaryCode("E_MISLOAD_ERROR"); return $FALSE; } # # find out last load # $finishedLine = ""; $beginningLine = ""; $indLines = $#{ $ContentsLoadMsg }; if(!$MISValue{ MIS_DBTYPE } || $MISValue{ MIS_DBTYPE } eq 'db2') { $beginload = 'The utility is beginning'; $endload = 'The utility has finished'; } else { $beginload = 'SDFMISLD01'; $endload = 'SDFMISLD02'; } foreach $ind (reverse(0 .. $#{ $ContentsLoadMsg })) { last if($finishedLine && $beginningLine ); if( ${ $ContentsLoadMsg }[ $ind ] =~ /\Q$endload\E/ ) { $finishedLine = ${ $ContentsLoadMsg }[ $ind ] . " " . ${ +$ContentsLoadMsg }[ $ind + 1 ]; } elsif( ${ $ContentsLoadMsg }[ $ind ] =~ /\Q$beginload\E/ ) { $beginningLine = ${ $ContentsLoadMsg }[ $ind ] . " " . ${ + $ContentsLoadMsg }[ $in d + 1 ]; } } # # Last load # my ($bday, $bmon, $byear, $bhour, $bmin, $bsec); my ($eday, $emon, $eyear, $ehour, $emin, $esec); if(!$MISValue{ MIS_DBTYPE } || $MISValue{ MIS_DBTYPE } eq 'db2') { ($bday, $bmon, $byear, $bhour, $bmin, $bsec) = $beginningLine =~ /"(\d){2}-(\d){2}-(\d){4} (\d){2}:(\d){2} +:(\d){2}/; #" ($eday, $emon, $eyear, $ehour, $emin, $esec) = $finishedLine =~ /"(\d){2}-(\d){2}-(\d){4} (\d){2}:(\d){2}: +(\d){2}/; #" } else { ($byear, $bmon, $bday, $bhour, $bmin, $bsec) = $beginningLine =~ /^(.){10} (\d){4}-(\d){2}-(\d)}-(\d){2}\. +(\d){2}\.(\d){2}/; ($eyear, $emon, $eday, $ehour, $emin, $esec) = $finishedLine =~ /^(.){10} (\d){4}-(\d){2}-(\d)}-(\d){2}\.( +\d){2}\.(\d){2}/; } use Time::Local; my ($timebegin, $timeend); if(!$beginningLine) { $timebegin = 0; } elsif(!$beginningLine) { $timeend = 0; } else { $timebegin = timelocal($bsec, $bmin, $bhour, $bday, $bmon - 1 +, $byear); $timeend = timelocal($esec, $emin, $ehour, $eday, $emon - 1 +, $eyear); } my $bdiffhours = (time() - $timebegin)/3600; my $ediffhours = (time() - $timeend )/3600; if( $bdiffhours > $Configuration{ MIS_MAX_DALLOADTIMEPASS_H } ) { &ResCode("WARNING"); &BrowseCode("Last DAL load operation was started more than $C +onfiguration{ MIS_MAX_DA LLOADTIMEPASS_H } hours ago"); $status = $WARNING; } else { &ResCode("OK"); &BrowseCode("Last DAL load operation started at " . timelocal +($timebegin)); } if( $ediffhours > $Configuration{ MIS_MAX_DALLOADTIMEPASS_H } ) { &ResCode("WARNING"); &BrowseCode("Last DAL load operation ended more than $Configu +ration{ MIS_MAX_DALLOADT IMEPASS_H } hours ago"); $status = $WARNING; } else { &ResCode("OK"); &BrowseCode("Last DAL load operation ended at " . timelocal($ +timeend)); } 
 if( $status == $TRUE ) { &SummaryCode("OK"); } elsif( $status == $WARNING ) { &SummaryCode("WARNING"); } else { &SummaryCode("E_MISLOAD_ERROR"); } return $status; }
.. there.. and that "module" is now a whole 3k shorter than it was, and no doubt a deal faster..

C.


In reply to Re: Code refactoring challenge by castaway
in thread Code refactoring challenge by castaway

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.