[Israel.pm] A regexp question

Gaal Yahas gaal at forum2.org
Mon May 17 06:33:15 PDT 2004


On Mon, May 17, 2004 at 01:04:59PM +0000, Mikhael Goikhman wrote:
> On 17 May 2004 15:33:09 +0200, Itzik Lerner wrote:
> >   $mac=~s/([\dA-Fa-f]{1,2})[:-]?/sprintf "%02X",$1/eg;
> 
> Two technical notes for those who want to learn.  The "[:-]?" substring
> does not contribute anything useful in this example, and there is a bug,
> a missing hex() function. The correct statement is:

FWIW, Perl allows a templated %s, so you can skip the call to hex:

     $mac=~s/([\dA-Fa-f]{1,2})[:-]?/sprintf "%02s",$1/eg;
                                                ^

-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/



More information about the Perl mailing list