Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Please help me with this conditional loop on text entries.

by lidden (Curate)
on Dec 14, 2007 at 07:03 UTC ( [id://656999] : note . print w/replies, xml ) Need Help??


in reply to Please help me with this conditional loop on text entries.

You cannot just remove the dots like you are doing. That will make different numbers like 127.0.0.1 and 12.70.0.1 look the same. You could expand the numbers to all be three digit numbers, remove the dots and then compare them, but I am sure someone will give a better solution.

Replies are listed 'Best First'.
Re^2: Please help me with this conditional loop on text entries.
by tachyon-II (Chaplain) on Dec 14, 2007 at 07:55 UTC

    Here is how to convert from a dot quad to the real unsigned 32 bit integer it represents and back again

    use Socket; for my $dot_quad ( "0.0.0.1", "127.0.0.1", "192.168.0.1" ) { my $integer = unpack "N", inet_aton($dot_quad); my $ip = inet_ntoa(pack "N", $integer); print "$ip\t int:$integer\n"; }