RoyCrowder has asked for the wisdom of the Perl Monks concerning the following question:
In Perl version 5.8.6 this code works correctly giving the correct dotted quad from the network. In v5.8.8 it gives back a weird dotted quad that looks like this: 216.55333.14165328.3626324100. I am using this IP 216.37.80.132 to test with.sub dotted_quad_to_network { my ($dq_address) = @_; $dq_address =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/; return (($1 << 24) + ($2 << 16) + ($3 << 8) + $4); } sub network_to_dotted_quad { my ($address) = @_; return sprintf ("%d.%d.%d.%d", $address >> 24, ($address << 8) >> 24, ($address << 16) >> 24, ($address << 24) >> 24); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Converting between network and dotted quad. Issue with << and >> operators between Perl Versions.
by zwon (Abbot) on Apr 13, 2009 at 17:34 UTC | |
by RoyCrowder (Monk) on Apr 13, 2009 at 17:41 UTC | |
by ikegami (Patriarch) on Apr 13, 2009 at 17:53 UTC |