in reply to IP to hex translator

Fore.

$ perl -MSocket -e 'printf(("%02x"x4)."\n",unpack"C4",inet_aton shift) +' 127.0.0.1 7f000001

Update: Granted there's no error checking as the OP's, but that's a single regex at worst (and is left as an exercise for the reader . . . :).

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: IP to hex translator
by lodin (Hermit) on Aug 14, 2008 at 15:12 UTC

    ... and you don't even have to write the pattern yourself.

    use Regexp::Common 'net'; $ip =~ /^$RE{net}{IPv4}\z/ or die;

    lodin