in reply to Re: Need to calculate IP address
in thread Need to calculate IP address

Hello Anonymous Monk,

For some reason, none of the solutions below wanted to work within my script.. Can you try this one, if it is working?

It is really strange that you need to do this much work, read and write to a file for IP manipulations.

#!/usr/bin/env perl use strict; use warnings; use NetAddr::IP; use feature 'say'; my $final; my $input = '127.0.0.3'; my @ip = split /\./, $input; if ($ip[3] % 2) { $final = join '.', @ip; $final = NetAddr::IP->new($final.'/8') + 1; } else { $final = join '.', @ip; $final = NetAddr::IP->new($final.'/8') - 1; } $final = substr $final, 0, -2; say $final; __END__ $ perl test.pl 127.0.0.4

BR / Thanos

Seeking for Perl wisdom...on the process of learning...not there...yet!