note
sulfericacid
Not the cleanest but it works. BTW you can't also separate on 0, all you care about is the unique octect that does not == 255. Your logic was a little off.<br><br>
My route: I dumped the entire IP address array inside the subnet array for simplicity. Then I iterated over the subnet array and did the calculations and 0 assignments.
<code>
sub getmask
{
push(@sub, @ip);
my $cnt = -1;
foreach my $line (@mask)
{
$cnt++;
if ($line != 255)
{
if ($flag > 0) { $sub[$cnt] = 0; }
my $magic = 256 - $line;
my $rem = $ip[$cnt] / $magic;
$rem =~ s/\.(.+)//;
$sub[$cnt] = $magic * $rem;
}
}
print join(".", @sub);
</code>
922645
922645