http://www.perlmonks.org?node_id=465353

mojobo has asked for the wisdom of the Perl Monks concerning the following question:

hi all, i'm building some fun perl one-liners for use with external programs and such.. i found a cool perl script that i converted to a single-liner that computes the network address of a unix machine:
this computes the network address..
perl -e '$ip="192.168.10.2"; $mask="255.255.254.0"; @maskbyte=split /\ +./,$mask; @ipbyte=split /\./, $ip; for($i=0;$i<4;$i++) { $b1=$maskbyt +e[$i]+0; $b2=$ipbyte[$i]+0;$NetByte=$b1&$b2; if($i != 0) {$NetAddr = +$NetAddr . "." . $NetByte; } else { $NetAddr=$NetByte ;}} print "$Net +Addr\n";'
now i'm trying to get the broadcast address, but i'm having some problems converting the 1's complement of the subnet mask back to something readable..
here's what i have so far:
perl -e '$ip="192.168.10.0"; $mask="255.255.254.0"; @maskbyte=split /\ +./,$mask; @ipbyte=split /\./, $ip; for($i=0;$i<4;$i++) { $b1=$maskbyt +e[$i]+0; $b2=$ipbyte[$i]+0; $NetByte=$b2 || ~$b1 ; if($i != 0) {$Ne +tAddr = $NetAddr . "." . $NetByte; }else { $NetAddr=$NetByte ;}} prin +t "$NetAddr\n";'
the one's complement of the subnet mask orred with the network address (formula for broadcast) gives a funky number..

192.168.10.4294967295