in reply to Need to calculate IP address

#!/usr/bin/perl # http://perlmonks.org/?node_id=1206349 use strict; use warnings; print "Enter the IP address\n"; my $tunip = <STDIN>; chomp ($tunip); print $tunip =~ s/\d+$/ ($& - 1 ^ 1) + 1 /er, "\n";

Updated conversion

Updated again

Replies are listed 'Best First'.
Re^2: Need to calculate IP address
by haukex (Archbishop) on Dec 28, 2017 at 19:34 UTC
    s/\d+$/ $& ^ 1 /er

    A neat solution, of course, but unfortunately it doesn't meet the OP's specs: .5 becomes .4 and .6 becomes .7.

      I think the example is wrong. What should a 0 become? Or a 9?

        It will never be a 0. If the IP ends in .9, it needs to become .10. .10 would become .9. .29 would become .30, etc.