Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Refactoring challenge.

by dws (Chancellor)
on Mar 06, 2005 at 17:41 UTC ( [id://437067]=note: print w/replies, xml ) Need Help??


in reply to Refactoring challenge.

This code is a mess, but works. Can you refactor it?

Sure. First, show me your unit tests, so that I can have confidence that my refactorings aren't breaking any unstated assumptions. In particular, on first read of the code, I'd want to see the tests that demonstrate (and document) what you expect

$str =~ s[^.{$pos1}\s*][];
to do and not do. Otherwise, I'd be left making educated guesses. That might work, or it might not.

Replies are listed 'Best First'.
Re^2: Refactoring challenge.
by BrowserUk (Patriarch) on Mar 06, 2005 at 18:32 UTC
    $str =~ s[^.{$pos1}\s*][];

    removes $pos1 characters from the front of the string, plus (optionally) any whitespace that immediately follows them. Not complicated but necessary.

    As for the unit tests, that would require I publish several hundred lines of support code, which would be a bit much to expect any to look through.

    Otherwise, I'd be left making educated guesses. That might work, or it might not.

    Fair enough. I wasn't asking for a perfect working solution, just some fresh ideas to set me on my way, which dragonchild and hv both gave me.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
Re^2: Refactoring challenge.
by BrowserUk (Patriarch) on Mar 07, 2005 at 01:03 UTC

    There is a testcase at 437114.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-24 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found