Sorry, I thought that ...chose/adjust the type (scalar/array/hash) of the closure... was fairly clear. The problem was that during the life of the utility sub, as a result of it's use, it may be beneficial to change the form in which the retained state is stored.

For example, when the sub is generated, the parameters supplied to the instantiator might indicate that an array would be the best representation. However, in use, the sub might determine that the data being retained is sparse data and therefore it makes more sense to revert the storage format to using a hash rather than an array. The reverse situation might also apply.

I was looking for some way for the utitlity sub to change the type (scalar/array/hash) of the closure on the fly. It turns out that I was simply looking for a complicated solution when a simple one would suffice. Zaxo++ pointed out (via /msg) that if the closure defined at construction time is a simple scalar I can later assign a reference to either an array or a hash as I decide I need and that addresses the problem.

I'm embarrassed that I didn't see the obvious myself before posting, but I didn't:(


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

In reply to Re: Re: Can a sub generate a closure from within itself? by BrowserUk
in thread Can a sub generate a closure from within itself? by BrowserUk

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.