Converting IP addresses to decimal and back again

sub ip2dec { return unpack('N', pack('C4', split(/\./, $_[0]))); }
sub dec2ip { return join '.' => map { ($_[0] >> 8*(3-$_)) % 256 } 0 .. 3; }

Comments