Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^7: timer without modules

by Random_Walk (Parson)
on Nov 10, 2009 at 14:26 UTC ( #806225=note: print w/ replies, xml ) Need Help??


in reply to Re^6: timer without modules
in thread timer without modules

Just do the test and store the time when the user calls the function.

# code not tested use strict; use warnings; my %called; my $interval = 60; # how long before they can call it again sub something { my $user = shift; # pass the function the name of the user calling + it my $now = time; return if exists $called{$user} and $now < $called{$user} + $inter +val; $called{user} = $now; # do the costly funtion }

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!


Comment on Re^7: timer without modules
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2014-07-24 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls