1. Move code in nested for/while loops into their own subroutine.
  2. Move the giant if/elsif conditions into their own subroutine and refactor till it makes sense.
  3. Making this into an object would simplify refactoring(for the if/elsif checks) because you can make a subroutine to do the conditional check that is more descriptive than 3 or 4 lines of if $blah == 2 and $blah2 < 2 and etc...
  4. If you have a subroutine that is longer than the size of your screen (80 rows or so) it is too long.
  5. If you have lines of code that are stretching over 80 lines in length then try another way to write the code. There is nothing worse than missing something because it goes off the screen.

In reply to Re: Refactor huge subroutine by Herkum
in thread Refactor huge subroutine by est

Title:
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.