Hello great monks!

I have a design problem, which ought to be simple but is confounding me. I have a package containing a variety of functions to help me deal with my data, which is in large arrays. I am having troubles abstracting a change to my code. Currently I have:

sub processA { # common stuff # special stuff } sub processB { loop (1..1000) { # common stuff # special stuff } }

I want to make this into something more modularized for a variety of reasons, so I was considering something like this:

sub processA { common_stuff($); # special stuff } sub processB { loop (1..1000) { common_stuff($); # special stuff } } sub common_stuff { # common stuff }

Pretty straight-forward, I guess. The problem is that as it stands now, the repeated code section (#common stuff) constructs a large array, then manipulates it. With my proposed modification, I would be creating this array for every iteration of the loop in processB. That isn't acceptable from a performance stand-point. So, I want something that may not be possible (or that may be, and I just don't know the term for it!):

Basically I want some way to create a large array in a sub-routine, keep it around as long as I need, and then to get rid of it. And preferrably I'd still want to keep this all in a single package.

Am I dreaming, or misguided, or naive, or lost? :)


In reply to Design Question by Anonymous Monk

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.