
Anthony
Deleted
Mar 27, 2000, 4:38 PM
Post #1 of 2
(646 views)
|
|
So close .. so very, very close
|
Can't Post
|
|
Been around more than once on similar topics and I am so close to a result I can taste it (ASCII, for those of you that don't know, is sorta tangy, sorta sweet). So, scenario: Each time a user hits the submit button, the following is supposed to happen. 1)User name and current time is written to a file in the form: $user|$time 2)Check to see if no one has posted in ten minutes, and if they haven't, I assume they are no longer active and they should be erased from the list. So, I have come up with this: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> $date = time(); $late = $date - 600; $old = "$whodir/$whofile"; $new = "$whodir/$whofile.tmp"; open (NEW,">$new") or die "Egads!: $!"; flock(NEW, 2); %userlist = (); foreach $line (@append) { @edit = split(/\|/, $line); $userlist{$edit[0]} = $edit[1]; } while ( ($k,$v) = each %userlist) { if ($v <= $late) { delete $userlist{$k}; } if ($k eq $user) { $userlist{$k} = $date; } else { $userlist{$k} = $v; } } while ( ($k,$v) = each %userlist) { print NEW ("$k|$v"); } flock(NEW, 8); close (NEW); rename ($new, $old); </pre><HR></BLOCKQUOTE> First, this isn't the whole code .. the rest creates OLD, reads OLD and etc. This section is supposed split the entries, push them into a hash as key,value .. reassemble the hash (deleting keys that have $late values) and print out the new hash (with keys that have no late values). Problem: Am I evaluating time wrong? Cause when the NEW is recreated, the late user is still there. Anthony [This message has been edited by Anthony (edited 03-27-2000).]
|