[Israel.pm] A regexp question

David Baird david.baird at homemail.com
Mon May 17 06:23:07 PDT 2004


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

> $m16 = join '',
>        map { sprintf "%02X", hex $_ }
>        split /[:-]/, $mac;

A matter of opinion...

I love these two examples of solving the same problem. I am sure that
lovers of the regex pattern language will look at the first and say,
"Oh, that is so pure regex" and use it. I, on the other hand, prefer the
more programmatic, regex light approach. I think it is more clear what
is happening. When I read it, I get a clear understanding from the code
what is supposed to happen.

-David




More information about the Perl mailing list