Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: inline caching a list-generating sub

by Roger (Parson)
on Aug 19, 2005 at 12:03 UTC ( #485090=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://485090]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2022-12-09 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?