develooper Front page | perl.beginners | Postings from March 2011

Re: transposing %d values to %x output

Thread Previous | Thread Next
From:
John W. Krahn
Date:
March 29, 2011 23:03
Subject:
Re: transposing %d values to %x output
Message ID:
20110330060321.13811.qmail@lists-nntp.develooper.com
Shawn H Corey wrote:
> On 11-03-29 07:50 PM, Noah Garrett Wallach wrote:
>>
>> s/(\d+)\.(\d+)\.(\d+)\.(\d+)/$1:$2:$3:$4::0/
>>
>> so is there a slick, easily readable way to get the value $1, $2, $3, $4
>> to be rewriten as %x instead of a %d?
>
> s/(\d+)\.(\d+)\.(\d+)\.(\d+)/sprintf('%x:%x:%x:%x::0',$1,$2,$3,$4)/e;

Might be better as:

sprintf '%x:%x:%x:%x::0', /(\d+)\.(\d+)\.(\d+)\.(\d+)/;

So you don't have to use eval.


John
-- 
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About