blankdon has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Representing a 32-bit integer
by jettero (Monsignor) on May 22, 2007 at 19:48 UTC | |
by Thelonius (Priest) on May 22, 2007 at 20:35 UTC | |
|
Re: Representing a 32-bit integer
by NetWallah (Canon) on May 22, 2007 at 22:00 UTC | |
|
Re: Representing a 32-bit integer
by Zaxo (Archbishop) on May 22, 2007 at 20:13 UTC |