Turning number ranges into prefixes
McGlinchy, Alistair
Alistair.McGlinchy at marks-and-spencer.com
Wed Aug 23 19:57:11 BST 2006
Dave,
> > Sorry, there was some magic I was missing; I half-remembered this
> > hack, which I think is either due to Nicholas or Damian. Given
> > ($a ^ $b) =~ /^(\0+)/,
> > the common prefix between $a and $b is ...
>
> 14242, but that is also the prefix for 1424277777, which is
> outside the range.
Maybe have a look at Net::Netmask. There's a sub in there called
irange2cidrlist which finds the smallest number of network blocks to
cover a given range of IP addresses which is sort of what you want.
<waves hands madly> I presume the binary manipulation in this module can
be munged like the above. The code is short on comments though (ie
none) so may be like turning a sausage back into a pig .
Interesting problem though. I may ponder further ...
Cheers,
Alistair
**********************************************************************
Registered Office:
Marks and Spencer plc
Waterside House
35 North Wharf Road
London
W2 1NW
Registered No. 214436 in England and Wales.
Telephone (020) 7935 4422
Facsimile (020) 7487 2670
<<www.marksandspencer.com>>
Please note that electronic mail may be monitored.
This e-mail is confidential. If you received it by mistake, please let us know and then delete it from your system; you should not copy, disclose, or distribute its contents to anyone nor act in reliance on this e-mail, as this is prohibited and may be unlawful.
2005
More information about the london.pm
mailing list