Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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. :)

In reply to Re: Re: CGI chat room problem by mt2k
in thread CGI chat room problem by Anh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-19 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found