Insert IP address into MySQL int field

Greets all,

I'm using Perl trying to insert an IP address from a log file into an INT field in a MYSQL table. So it needs to be converted into an int first. I thought the pack() function could do this for me, but I'm not sure I get the right thing. I also need to be able to extract it correctly later. Am I doing it right? If so, what code do I need to extract it?

($ip,$url) = <some regular expression>
$ipaddr=pack("I",split(/\./,$ip);
$dbh->do("insert into entry values ( $url, $ipaddr );");

From perldoc -f pack:

So you could do

use Socket; 
$ipaddr_decimal = unpack ("N", inet_aton ("192.168.1.1"));
$ipaddr = inet_ntoa(pack ("N", $ipaddr_decimal));

Thanks. This works well. But is there a 'perl' way of doing the inet_aton conversion? That seems a little 'heavy'.

IMHO inet_aton() is pretty lightweight, I think there is no other embedded way of doing this. Maybe you could create a sub to transform an IPv4 address into network byte order but that's just the point of inet_aton().