Convert Integer To IP Address


Of an acquaintance, I got the assignment to write a function that converts an integer to an IP address. An IP address is really just another way to represent an integer. Below is an example of the solution I came up to. This code is written in Perl.

my($int) = $ARGV[0]; #Receives an integer as an argument.
my(@ip); #An array that holds the octets of the IP address.
for(my($i) = 0; $i < 4; $i++)
  $ip[$i] = $int % 256;
  $int = ($int - $ip[$i]) / 256;