Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: calculate subnet help

by sulfericacid (Deacon)
on Aug 26, 2011 at 15:39 UTC ( #922681=note: print w/replies, xml ) Need Help??


in reply to calculate subnet help

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.

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.
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);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://922681]
help
Chatterbox?
[Discipulus]: hippo take a look at Re^2: Cookie->fetch problem
[Discipulus]: oh and dont miss my last poetry!
[marioroy]: Hello all. After several attempts, am able to move forward and will soon release a Parallel:: ForkManager compatible MCE::Hobo:: Manager, also MCE::Hobo::Simple, and refactored MCE::Hobo engine supporting multiple instances. Wait works beautifully.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2017-05-26 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?