Well, I think I'll choose this:
$mac =~ s/([0-9a-fA-F]{2})\B/$1:/g;
which can be also spelled as:
$mac =~ s/(\p{Hex}{2})\B/$1:/g;
The
[:xdigit:] class does not work (I don't know why).
@Not_a_Number: probably there isn't a reason to prefer a regex over 'unpack' or the use of a module, in this case, since this regex is not really more readable than other methods.
Anyway I'm more familiar with regexes than with unpack or the Net::MAC module, so there is a chanche that I will recognize and understand that sooner when looking again at my code in the future.
As for modules, I often avoid (or completely overlook) them, because I usually have little or no control on the systems I work onto (so installing a module can be a tricky or impossible task). I see that "use a module" vs "reinvent the wheel" is an ever discussed problem. I'm on the "reinvent the wheel" side, but it's not my fault :)
Thanks to all,
bye.
Edit:
jut in case someone come here in the future.
[:xdigit:]
actually works:
$mac =~ s/([[:xdigit:]]{2})\B/$1:/g;
I just didn't put enough square brackets.
[:xdigit:] is equivalent to
[:xdigt] (literally), while
[[:xdigit:]] is equivalent to
[0-9a-fA-F]. Reading the f. manual helps as usual :)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.