in reply to IP Iterator

1. I guess you didn't know there is ++ operator? :) You can write your code $ip[3] = $ip[3] + 1; as $ip[3]++

2. Do you know you can call function with splices? func($arr[0], $arr[1], $arr[2], $arr[3]) is the same as func(@arr[0..3]);

3. Your function nextIp() would be two/three lines long if you operated on simple 32-bit int, passed 32-bit int to ping() function and there converted to IP like this:

$ip = $_[0]; # your 32-bit int $arr[3] = $ip & 255; $ip >>= 8; $arr[2] = $ip & 255; $ip >>= 8; $arr[1] = $ip & 255; $ip >>= 8; $arr[0] = $ip & 255;

Replies are listed 'Best First'.
Re^2: IP Iterator
by camlet (Novice) on Apr 17, 2008 at 15:10 UTC
    2.) array worked thanks my code got better. i made the change.

    3.) still working on understanding the change but would the solution include incrementing the next octet if $_[i-1] hits 255?

      3) the recommended change doesn't include verifying octet[i-1]

      $ip = $_[0]; # your 32-bit int $arr[3] = $ip & 255; $ip >>= 8; $arr[2] = $ip & 255; $ip >>= 8; $arr[1] = $ip & 255; $ip >>= 8; $arr[0] = $ip & 255;