in reply to Re: Re: Re: decimal -> hex
in thread decimal -> hex

...and slightly shorter|more extensible (if perhaps less efficient) way:

my $hex_addr=join '.',map {sprintf "%02x",$_} split /\./,$address;

Or even:

(my $hex_addr=$address)=~s/(\d+)/sprintf("%02x",$1)/gx;

...although of course the results could be a bit funny if it's not an IP address.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: decimal -> hex
by Anonymous Monk on Oct 13, 2002 at 07:34 UTC

    Curses! I got distracted by the coolness of /x. I meant of course (particularly given the context):

    (my $hex_addr=$address)=~s/(\d+)/sprintf("%x",$1)/ge