Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How will you use state declared variables in Perl6?

by theorbtwo (Prior)
on Jul 09, 2005 at 04:39 UTC ( #473641=note: print w/ replies, xml ) Need Help??


in reply to How will you use state declared variables in Perl6?

I think I'll likely use state vars mostly the same way I used the equiv p5 code: {my %foo; sub get_cached {my $x=shift; return $foo{$x} if exists $foo{$x}; $gotten = get($x); $foo{$x}=$gotten; return $gotten}.

It's really quite useful when you want to create a quick-and-dirty cache without pulling in lots of dependencies you could easily avoid. Of course, complicate to taste with an expiration strategy, which I generally do in conjunction to cache loading.


Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).


Comment on Re: How will you use state declared variables in Perl6?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-08-23 19:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (178 votes), past polls