in reply to Can a sub generate a closure from within itself?

Even with your update, its still totally unclear what you're asking for. What do you mean by the 'type' of a closure?
  • Comment on Re: Can a sub generate a closure from within itself?

Replies are listed 'Best First'.
Re: Re: Can a sub generate a closure from within itself?
by BrowserUk (Patriarch) on Apr 24, 2004 at 13:45 UTC

    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