robbyrussell at pdxlug.org
Tue Jul 29 16:50:13 CDT 2003
> On (Tue, Jul 29 10:57), Robby Russell wrote:
> I'm not sure which is more important to you:
> 1. That the IPs are readily accessible.
> 2. That the IPs are easily expirable.
> In the first case your data-structure looks good. If it's the second
> case, then I'd suggest using a heap instead. Heaps have the handy
> ability to remain sorted, by say, timestamp.
> Here's a quick mockup of a heap implementation using Heap::Simple,
> found on CPAN. There are other heap modules out there, this just
> happens to be the one I have on my system.
> #!/opt/perl580/bin/perl -w
> # ip_ts_heap.pl - Store IPs in a heap indexed by timestamp
> # jkeroes at eli.net 29 Jul 2003
> use strict;
> use Heap::Simple;
> use Data::Dumper;
Thanks for the suggestion. I actually came across Tie::IxHash and it seems
to do the trick
Since my hash contains the key ip and the value (an array) I just created
a function that loops through the hash and runs a diff on the 
timestamp in the array and the current time. If it's > defined seconds,
it deletes the hash record.
Thanks again for your help!
Portland Linux User Group
More information about the Pdx-pm-list