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:

my @range= unpack "N*", pack "C*", split /[. ]+/, "@ARGV";
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:

$range[0]..$range[1]
with such large numbers. That causes Perl to squawk:
Range iterator outside integer range at ...
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:

for( $_= $range[0]; $_ <= $range[1]; $_++ )
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:
sub octets2num { my $val= 0; for( split /\./, shift(@_) ) { $val= 0x100*$val + $_; } return $val; } sub num2octects { my $val= shift(@_); my @bytes; while( 0 < $val ) { unshift @bytes, $val%0x100; $val= int( $val / 0x100 ); } return ! @bytes ? "0" : join ".", @bytes }
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 reply to (tye)Re2: BigInt usage by tye
in thread BigInt usage by ryan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.