in reply to Code refactoring challenge

First things first. You'll have to explain to us why we're trying to reinvent the wheel with functions like "FileExists"...
if( ( $statusLoadmsg = &FileExists( $logFile ) ) == $FALSE ) { &ResCode("WARNING"); &BrowseCode("File \"$logFile\" not found"); 
 &SummaryCode("WARNING"); return $WARNING; }
Maybe...
do {warn "$logfile not found"; return $warning} unless -e $logfile;
would do?
# # read whole log file # if( &readFileContents( $logFile, $ContentsLoadMsg ) == $FALSE ) { &ResCode("E_LOADMSG_ERROR"); : &BrowseCode("Could not open \"$logFile\""); 
 &SummaryCode("E_MISLOAD_ERROR"); return $FALSE; }
...Hmm, is "readFileContents" any different than $contents = <$logfile>;(with $/=undef)? Then of course we have to ask why bother with the exsistance check in the first place. Oh, and what's up with all the $TRUE and $FALSE. Looks ugly and error prone to me. And by the description in the update, I'd guess you should be able to do what you want in less than 10 lines of code.

Replies are listed 'Best First'.
Re^2: Code refactoring challenge
by castaway (Parson) on Apr 30, 2005 at 08:45 UTC
    I know the code is crap. That's why I went to rewrite it! I didn't write it myself, I just maintain the bugger. Yes, its fugly, but its gotten the job done for the last year or two, (although adding even "use warnings" makes a pretty mess) .. I think this guy was a perl4ish programmer.

    Whatever, the exercise was not to pick holes in the crap that's already there, but write those 10 lines you claim ;)

    C.

      Whatever, the exercise was not to pick holes in the crap that's already there, but write those 10 lines you claim
      Well, the easiest thing would be to start over I think. Why don't you post the desired output for the data sample you provided (instead of having us try to compile and run the original program in our heads).