Jeff Pang schreef:

> I have a text file which contains lots of IPs,like:
> 58.253.0.0/16;
> :
> 60.3.0.0/16;

Is it always /16? Can they overlap?


> My question is,[ ]given an IP,[ ]ie 59.32.232.33,[ ]how
> can I know it exists in this file or not?

exists? ITYM: matches (they are masks)

You could build a byte (or nibble) oriented hash, and walk the tree.

But if the masks *cannot* overlap, then put them in a sorted array, and
do a binsearch, and AND the ip-nr with the nearest mask <= ip-nr.

-- 
Affijn, Ruud

"Gewoon is een tijger."


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to