in reply to Need to calculate IP address

G'day ddrew78,

"Any wisdom at all would be greatly appreciated."

It would be wise to:

Furthermore, your descriptive text and programmed logic are at odds with each other:

$ perl -E 'my @x = split /\./, "10.1.1.5"; $x[3] % 2 ? --$x[3] : ++$x[ +3]; say join ".", @x' 10.1.1.4 $ perl -E 'my @x = split /\./, "10.1.1.6"; $x[3] % 2 ? --$x[3] : ++$x[ +3]; say join ".", @x' 10.1.1.7

You could reverse the logic to match the text:

$ perl -E 'my @x = split /\./, "10.1.1.5"; $x[3] % 2 ? ++$x[3] : --$x[ +3]; say join ".", @x' 10.1.1.6 $ perl -E 'my @x = split /\./, "10.1.1.6"; $x[3] % 2 ? ++$x[3] : --$x[ +3]; say join ".", @x' 10.1.1.5

But then you'd have edge case problems not addressed by either your description or code:

$ perl -E 'my @x = split /\./, "10.1.1.0"; $x[3] % 2 ? ++$x[3] : --$x[ +3]; say join ".", @x' 10.1.1.-1 $ perl -E 'my @x = split /\./, "10.1.1.255"; $x[3] % 2 ? ++$x[3] : --$ +x[3]; say join ".", @x' 10.1.1.256

So, there's potentially issues at a fundamental level (e.g. problem analysis, solution design, coding logic); and there's clearly problems with a lack of basic checking and validation.

— Ken