++BrowserUK for the simplification of the right hand side, but the only problem with the version I first posted was just the placement of the + outside the capturing parenthesis.

The :? was only there to remove the : not to delimit (correct word i hope), where the regular expression would stop matching but to remove it if it existed after a string of characters in [0-9A-F]. Thus the (?::|$) is unnecassary, as it will stop when it hits something outside [0-9A-F] anyway, whether it is a colon or the end of the line.

After further thought the reason:

$foo =~ s/([0-9A-F])+:?/length($1) < 2?"0$1":$1/ge;
does not work how it was intended is because ([0-9A-F])+ in the B8 part (the other parts worked because of a fluke of circumstance, but had they all been B8 the error would have been glaringly apparent), but I digress, the reason it did not work for the B8:, is that it first captures the B but the + makes it want more so it continues to with the 8 but since we don't have a + on the inside(ie. ([A-F0-9]+)) the B is tossed, well technically is part of the successful match, but the due to the placement of the + the $1 is now 8. Now, it tries for something else in this character class, but since there is nothing it continues to the next part of the expression, and since the : is the next thing it needs to match (if it is there, hence the ? after the :), it matches successfully, and life goes on, and if no one else learned anything from my spiel, I did, and that counts for something

-enlil


In reply to Re: Re: Re: Re: Converting MAC Address by Enlil
in thread Converting MAC Address by HiFoo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.