Pathologically Eclectic Rubbish Lister | |
PerlMonks |
(tye)Re2: BigInt usageby tye (Sage) |
on Feb 17, 2001 at 21:15 UTC ( [id://59126]=note: print w/replies, xml ) | Need Help?? |
Sorry, my previous reply was a bit of a quickie. I did some experiments and wanted to now more explicitly fill in some of the bits that you and I hinted at. Your original code and my modified version here: both work for any list of valid IP addresses in dotted-decimal notation, even those above 128.0.0.0. The problem comes when you try to do: with such large numbers. That causes Perl to squawk: Which was news to me; thanks for teaching me something. (: Your solution of using 0..$range[1]-$range[0] is quite good. You could also do: Both should work for even 56-bit integers (I don't recall IPv6 address notation...). Though, you can't use the "N" format for pack()/unpack() for more than 32 bits, so you'd need to build up the number: Note that using bit-wise operators (or use integer) above would break these. (I think using push instead of unshift and adding a reverse might be slightly more efficient.) Update: I couldn't help golfing the first line of code a bit. - tye (just playing; that's how I usually learn)
In Section
Seekers of Perl Wisdom
|
|