Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Legacy Code

by GotToBTru (Prior)
on Apr 01, 2011 at 15:26 UTC ( [id://896944]=perlmeditation: print w/replies, xml ) Need Help??

With apologies to Charles Schulz.
$nmbrvalues = 11; $position1 = 0; $position2 = 0; $linelength = length($linein); for ($cntr = 1; $cntr <= $nmbrvalues; $cntr++) { $position1 = $position2; $position1 = index($linein,'|',$position1); $position2 = index($linein,'|',$position1 + 1); $fldlength = $position2 - ($position1+1); if ($cntr == 1) {$hold1 = substr($linein,$position1+1,$fldlength);} if ($cntr == 7) {$hold2 = substr($linein,$position1+1,$fldlength);} if ($cntr == 8) {$hold3 = substr($linein,$position1+1,$fldlength);} if ($cntr == 9) { $position3 = $position1+1; $position3 = index($linein,'@',$position3); If ($position3 > 0) { if ($position2 < 0) {$position2 = length($linein);} $fldlength = $position2 - ($position1+1); $emailaddress = substr($linein,$position1+1,$fldlength); } #end of IF if ($position3 <= 0) {$emailaddress = "mgrs\@server.com";} } #end of if } #end of FOR
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
GGGGGGGGGGGGGGGGGGGGGGGHHHHHHHHHHHHHHHHHHHHHHH!


You may now resume your regularly scheduled Perlmonks browsing.



Update: corrected the misspelled name.

Replies are listed 'Best First'.
Re: Legacy Code
by GotToBTru (Prior) on Apr 06, 2022 at 12:25 UTC

    Recently came upon a similar block of code in a program which I've never had the need to fix in the last 11 years. That's the definition of legacy code, I guess.

    I knew the guy who wrote the original. It had to be really frustrating to write all that to do a really simple thing. I know he and others were frustrated that perl was the only tool available to them and they didn't know it. But to take the time to write that, instead of investing that time in learning a much, much better way ... I just can't imagine that.

    ($hold1, $hold2, $hold3, $emailaddress) = (split /\|/,$linein)[0,6,7,8 +];
    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Re: Legacy Code
by cavac (Parson) on Apr 06, 2022 at 19:12 UTC

    Ah yeah. Here's one of my own crimes. A quick&dirty way to allow for relative timestamps.

    sub parseWebdate { my ($str) = @_; if($str =~ /^([+-])(\d+)(\w)/) { my %multipliers = ( s => 1, m => 60, h => 60*60, d => 60*60*24, W => 60*60*24*7, M => 60*60*24*30, y => 60*60*24*365, ); my ($direction, $amount, $multiplier) = ($1, $2, $3); if(!defined($multipliers{$multiplier})) { croak("Undefined delta time multiplier $multiplier"); } if($direction eq '-') { $amount = $amount * -1; } return time() + ($amount * $multipliers{$multiplier}); } # normal time string return str2time($str); }

    When i wrote that, i told myself "It's only temporary, i'll clean it up next week". So far, it has been about 624 weeks on my Todo list and still going strong.

    perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
Re: Legacy Code
by repellent (Priest) on Apr 03, 2011 at 06:16 UTC
    Here, I've written the first test.

    Once you're done adding tests, you can modify foo() to your heart's content. The tests must still pass.
Re: Legacy Code
by jdporter (Paladin) on Apr 06, 2022 at 18:19 UTC
Re: Legacy Code
by eyepopslikeamosquito (Archbishop) on Apr 07, 2022 at 01:55 UTC

    Ah, the joys of legacy code. :) The "right" approach depends on how much code there is ... and what are the consequences if you break it. Millions of lines of crufty old business-critical code is the nightmare I've faced (and is faced daily by P5P ;-).

    My mandatory list of references on this topic: Re: Strategies for maintenance of horrible code? (Legacy Code References)

Re: Legacy Code
by holli (Abbot) on Apr 03, 2011 at 13:02 UTC
    You gotta love the end block comments!


    holli

    You can lead your users to water, but alas, you cannot drown them.
Re: Legacy Code
by sundialsvc4 (Abbot) on Apr 04, 2011 at 17:44 UTC

    s/Schultz/Schulz/g

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://896944]
Approved by wazoox
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-16 13:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found