Um, I think you mean s/\s+$// does the same job. But anyway, one of the limitations of sharing really bad code is that it's typically too long and too boring to make for a good joke, usually because the most frequent symptom of bad code is copy/paste programming.
I saw a script a few years back whose purpose was to produce a summary report every day, showing year-to-date quantities of data received from about two dozen sources -- so, roughly 24 lines of output. The solution? If "previous day" was the first day of January, no need to compute "year-to-date", so this makes up an "if" block with 24 distinct "print" statements, where the name of each data source is part of a distinct but otherwise identical string being printed, saying the count is 0 for each one. The else block was more "interesting": 24 copies of a 4-line block, where the source name was changed in 3 of the 4 lines. (And 2 of the lines were shell commands in back-ticks to assign strings to two variables being used in the print statements.)
As a bonus, here was the method at the top of the script for getting yesterday's date:
Based on this programmer's general concept of "logic", it's almost surprising that this part wasn't copied into each of the "if/else" blocks -- but it turns out he decided to get the previous day's date as well (though he never used that value), so he repeated the above block, adding a factor of 2 to the subtraction from "$nowsecond". And of course, both the "if" and "else" blocks contained their own copies of this essential "glue" operation:# get the date of yesterday my $nowsecond = time (); my $yestersecond = $nowsecond - 24 * 60 * 60; my @yesterdate = localtime ($yestersecond); my ($day, $month, $year) = ($yesterdate[3], $yesterdate[4], $yesterdat +e[5]); $day = sprintf("%.2d", $day); $month = sprintf("%.2d",$month+1); $year = $year + 1900;
This $datestr variable was dutifully copied into all 48 print statements.my $datestr = "$year.01.01-$year.$month.$day";
In reply to Re: TIMTOWTDI meets Rube Goldberg
by graff
in thread TIMTOWTDI meets Rube Goldberg
by Tanktalus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |