in reply to ip address calculations

For your first code, Perl 5.6.1 lets you do this kind of niftiness:

my ($s,$e) = unpack 'N2', .; printf("%vd\n",pack 'N',$_) for ($s..$e)
If you use this code, though (complete with whitespace sensitivity that makes Python look like a Good Idea), you might well be shot. Replace the unpacks with a more direct translation of dotted quadruplets into ints, e.g.
sub ip_to_num { my $ip = shift; my $n; $n = $n*256+$_ for (split /\./,$ip); $n }

For the second question (and, indeed, for the first), it would be best to post some code, or at the very least some sample input/output.

Replies are listed 'Best First'.
Re: Re: ip address calculations
by tachyon (Chancellor) on May 06, 2002 at 12:01 UTC
    my ($s,$e) = unpack 'N2', .; printf("%vd\n",pack 'N',$_) for ($s..$e) __DATA__ Range iterator outside integer range at line 2.

    This will fail on "real" addresses (that exceed integer range) as shown.