in reply to Re: decrementing numbers
in thread decrementing numbers
There are network-address functions...
use Socket; my $n32 = inet_aton("192.168.254.0"); print inet_ntoa(pack("N",unpack("N",$n32)-1)); # "192.168.253.255"
Or, in the OP's context:
s/(\d+\.\d+\.\d+\.\d+)/inet_ntoa(pack("N",unpack("N",inet_aton($1))-1) +)/e;
But (to quote the docs): "For portability do not assume that the result of inet_aton() is 32 bits wide, in other words, that it would contain only the IPv4 address in network order."
|
|---|