http://qs321.pair.com?node_id=485090


in reply to inline caching a list-generating sub

Something like this? :-)
sub foo { $list = $foo_cache{join ',', @_} ||= [ do { ... rest of sub goes here }]; want_array ? @$list : $list; }


Replies are listed 'Best First'.
Re^2: inline caching a list-generating sub
by Roy Johnson (Monsignor) on Aug 19, 2005 at 14:36 UTC
    Nicely written, but you're having it return a ref in scalar context, whereas the OP wanted it to behave like a list (which returns the last element). Change the last $list to $list->[-1]

    Caution: Contents may have been coded under pressure.