Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: CGI chat room problem

by mt2k (Hermit)
on May 04, 2002 at 01:23 UTC ( #163948=note: print w/replies, xml ) Need Help??


in reply to Re: CGI chat room problem
in thread CGI chat room problem

If you are indeed using a hash to hold times, this should do more or less what you want (this is what I use for something similar. The time distance is 3 minutes, so 3 minutes after they leave their name is removed.):

use Data::Dumper; #Next 2 lines make sure only one HTTP request deals with database at o +nce open LOCKFILE, ">>lock.lck" or die "Could not open the lock file!"; flock LOCKFILE, LOCK_EX or die "Could not flock the lock file!"; #database.dat holds the physical hash #a 'do' executes the file (rebuilds your time hash) do "database.dat"; #Get the current date values @date = localtime(); #loop through the %userTimes hash to find old entries foreach $user (keys(%userTimes)) { $last_hour = $userTimes{$user}{'hour'}; $last_min = $userTimes{$user}{'min'}; $cur_hour = $date[2]; $cur_min = $date[1]; $expire = 0; #Yes, if 3 minutes old $expire = 1 if ($last_hour == $cur_hour && ($cur_min - $last_min) >= 3 +); #there are some exceptions to the 3 minute deal. #the next lines cover this! if ($last_hour != $cur_hour) { $expire = 1 if $last_hour > $cur_hour; $expire = 1 if $last_min <= 57 && $cur_min >= 0; $expire = 1 if $last_min == 58 && $cur_min >= 1; $expire = 1 if $last_min == 59 && $cur_min >= 2; } if ($expire == 1) { delete $userTimes{$user}; #yep, delete them! } } #Output the hash to the database file thingy $Data::Dumper::Purity = 1; #Need this $Data::Dumper::Indent = 0; #saves some disk space open FILE, ">database.dat"; print FILE Data::Dumper->Dump([\%userTimes], ['*userTimes']); close FILE;
That's about it! The only thing you really need to concern yourself with is that subtracting the minutes is not good enough. There are some 'race conditions' you need to look at. :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2022-09-30 23:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (126 votes). Check out past polls.

    Notices?