Recently on one of my mailing lists, someone wanted some code to translate CIDR-style ip.add.re.ss/bits descriptions into the more traditional network address and netmask pairs. Another list member posted some perl code which was basically 30 lines of C but with extra $ signs sprinkled throughout. My version was (stripped of data validity checking etc) this:
my ($addr, $bits, $network, $mask) = split("/", $cidr);
$network = $network * 256 + $_ foreach(split(/\./, $addr);
$mask = eval '0b'.('1' x $bits).('0' x (32 - $bits));
print int2ip($network & $mask)."\t".int2ip($mask)."\n";
(the int2ip function was the same as that the original poster had used, so I don't bother reproducing it here)
The string eval - abhorred by many - meant I could avoid several lines of fairly opaque bit-banging and I think it's *very* clear what that line does, and it also makes it obvious how netmasks are related to the /bits in CIDR notation.