Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: inline caching a list-generating sub

by Roger (Parson)
on Aug 19, 2005 at 12:03 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others about the Monastery: (9)
As of 2024-04-23 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found