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 am going to suggest a completely different way of doing this.

You know what the script is used for, don't you? Well define your task into 2 interacting jobs:

  1. To write a library or libraries that make it easy to write acripts that do its task or tasks.
  2. To simplify this script by having it written in terms of that library or libraries.
If you were to take these two jobs to completion, you should have a clean library and a simple script. At present you are nowhere near this goal and have no idea how you are going to get there.


What you want to do is look at the script and identify something simple which might belong in a more general library that you can easily drop into the script. Found it? Good. Now start a simple module. You can use the following template:

package My::Module; # Magical export invocation. use Exporter; @ISA = 'Exporter'; @EXPORT_OK = qw(); # Will fill in # Rest of header section. use strict; # Body here. # Will fill in 1; __END__ =head1 NAME My::Module - Will fill in =head1 SYNOPSIS use My::Module; # Will fill in =head1 DESCRIPTION Will fill in =head1 BUGS AND LIMITATIONS None known.
Note that the name of the module should match the package name, in this case My/, and where it goes depends on your current development setup.

Now go to the hideous, ugly script and have it use your module. Next take that simple function or bit of functionality which you identified, and put it in your module. Put the name of it in @EXPORT_OK, describe it and then put it in the import list in your script. In other words put a bit in all the things which are, "Will fill in" above. Then replace a bit of the script with your brand new function.

Wash, rinse, and repeat, developing tests, refactoring your library, etc as necessary. At no step are you writing the script from scratch. But you are eating away at it, and eventually there will be little enough left that you can do the rewrite easily. Plus when you get done you have this convenient library.

Note that this approach is not doable with all kinds of scripts. But when it is appropriate, it can be a good path to know about from ugly legacy code to a cleaner design.

In reply to Re (tilly) 1: Best way to fix a broken but functional program? by tilly
in thread Best way to fix a broken but functional program? by idnopheq

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [Jenda]: Sorry, 29 questions on stackoverflow regarding Perl6 this month. What a lively community.

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (3)
    As of 2018-04-24 21:17 GMT
    Find Nodes?
      Voting Booth?