Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I just got a new client that has a bunch of Perl scripts in three almost identical copies.

The story is that they used to have set of scripts dealing with one kind of input. When they started to receive a slightly different set of input - from another source - they copied the scripts and slightly modified some of them to cope with the new input. Then this happened again so now they have 3 sets of almost identical code.

Naturally no unit tests are around.

In addition some of the subroutines were also copied among the files of the original set so I have some duplication there too.

Luckily all of the use strict and warnings and almost no globals so the code is not bad at all.

What would be the best approach to deal with this?

I thought it would be nice to track down the identically named subroutines in the codebase and then recognize if the subroutines are the same or nearly the same, showing the diff between the subroutines.

For extra bonus it would be nice if I could easily unite two almost identical scripts into a module and a scrip. (and what if I have 3 copies...).

So this is a real issue I have now - or rather I had as I manually worked through it in the past 2 days but actually this could be a nice tool and a nice plugin to an IDE.

So let me also add my promotional link here to the Vertical Metre of Beer 3 - The Padre Plugin Contest! I'd be glad to see people starting to write a plugin that can help us handle such a situation.

In reply to Refactoring copy-pasted code by szabgab

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2023-06-05 00:06 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (22 votes). Check out past polls.