Sure it can, if it has a single purpose you can put a name to.

To do that with ease, you can refine the big function bit by bit. Make sure that it doesn't assign to global variables, unless that's its sole purpose. Try to make the function return what it produces, getting all of its information from its arguments. That insulates the rest of the application from the functions' workings.

Now start cutting down big lists of initial my declarations, moving each lexical variable's declaration to where it is first assigned. Then move that assignment down to just before it is first used. Find where each variable is last used, and consider that spot for the end of a lexical block. The block which most closely corresponds to the new function you're thinking of will be the body of your new function. It will tell you which outer variables correspond to arguments of the new function, and which are internal to it.

This whole process is referred to as "refactoring", and it's worth the exercise to do it.

After Compline,
Zaxo


In reply to Re: Can a large subroutine be split in two (e.g. parent and child relationship)? by Zaxo
in thread Can a large subroutine be split in two (e.g. parent and child relationship)? by newbie00

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, details, 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, summary, 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.