On 11-11-27 04:46 AM, Dr.Ruud wrote:
On 2011-11-23 04:24, Arvind wrote:
[...] I want to convert an IP address of the form A.B.C.D into a
number that will serve as an index of the array. I want to do it in a
way that there is very low probability of the number created from
A.B.C.D being the same as that created from E.F.G.H.
Try a Bloom filter.
If that is too clashy, just use a multilevel hash:
$ip{ chr(127) }{ chr(0) }{ chr(0) }{ chr(1) } = 1;
It would be better to have the keys readable if the hash is dumped:
$ip{ 0+$A }{ 0+$B }{ 0+$C }{ 0+$D } = 1;
$ip{ 0+$E }{ 0+$F }{ 0+$G }{ 0+$H } = 1;
Or even better:
sub set_ip {
my ( $ip_address ) = @_;
my @ip_elements = map { 0+$_ } split /\./, $ip_address;
$ip{ join( '.', @ip_elements ) } = 1;
}
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication
as it is about coding.
Never give up your dreams. Give up your goals, plans,
strategy, tactics, and anything that's not working but never
give up your dreams.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/