in reply to Code refactoring challenge
Much better is
my $config = GlobalConfig->new; # compile-time error if ( $config->mis_dbtype = 'db2' ) { ... } # This works if ( $config->mis_dbtype == 'db2' ) { ... }
if( &readFileContents( $logFile, $ContentsLoadMsg ) == $FALSE ) { &ResCode("E_LOADMSG_ERROR"); &BrowseCode("Could not open \"$logFile\""); 
 &SummaryCode("E_MISLOAD_ERROR"); return $FALSE; }
Get rid of the ampersands. Also, why haven't you wrapped the contents of this if-block in a subroutine?
sub do_logging { my ($rescode, $browsecode, $summarycode) = @_; ResCode( $rescode ); BrowseCode( $browsecode ); NewLine(); SummaryCode( $summarycode ); } if ( readFileContents( $lofFile, $ContentsLoadMsg ) == $FALSE ) { do_logging( 'E_LOADMSG_ERROR', 'Could not open "$logFile"', 'E_MIS +LOAD_ERROR' ); return $FALSE; }
DateTime, Date::Calc::Object, Date::Manip ... use them!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}/; }
is better written as$finishedLine = ${ $ContentsLoadMsg }[ $ind ] . " " . ${ $ContentsLoad +Msg }[ $ind + 1 ];
$finishedLine = join ' ', @{$ContentsLoadMsg}[ $ind, $ind + 1 ];
The Perfect is the Enemy of the Good.
|
|---|