A function is to take a string containing an IP address, such as "192.168.11.5 <http://192.168.11.5/> ". Once it verifies that there's an IP address in the string, the function must produce and return a 32-bit integer representation.
$test1 = quadToInt("192.168.11.5 <http://192.168.11.5/> "); # $test1 would contain 3232238341.
The only way I know to get the representation is to use pack after replacing the '.'s with some numeric value like '0' i.e
# generate and return 32-bit integer representation of IP address $IPaddr =~ s/\./0/g; my $rep32bit = pack('N', "$IPaddr"); # unsigned long in 'network order +'
This returns 4294967295.
Question: how to get '3232238341' ?
Is there some other way in Perl to produce the 32-bit integer representation besides packing?
Edit: g0n - code tags and formatting
In reply to Representing a 32-bit integer by blankdon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |