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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.