in reply to comparing two ip addresses.

use Socket qw( inet_aton ); if (inet_aton('83.1.1.1') lt inet_aton('82.1.1.1')) { print("is less than\n"); } else { print("isn't less than\n"); }

All the string comparison operators (lt, gt, le, ge, eq, ne and cmp) work here.

This "trick" is also useful for sorting.

my @sorted_ips = map substr($_, 4), sort map inet_aton($_).$_, @ips;

You might also find the modules Net::IP or NetAddr::IP of interest.

By the way, the problem is your code is that you pad the elements of @calc, yet you use $*_start and $*_end (not the padded elements) to form $calc1 and $calc2.

Update: Added the sorting code and the list of relevant modules.
Update: Changed substr($_, 5) to substr($_, 4).
Update: Added the explanation as to why the OP's code didn't work.

Replies are listed 'Best First'.
Re^2: comparing two ip addresses.
by jonsmith1982 (Beadle) on Sep 16, 2006 at 12:14 UTC
    Thanks for pointing that out to me, i would of carried on making that mistake if it wasnt for you and perlmonks.