I think it is easier to calculate "final mac" directly from mac. I used a regex, but I couldn't figure out how to write it so that a final "." didn't appear at the end. I finally gave up and just ran another simple regex to ditch this unintended side effect at the end. I highly suspect that a more advanced regex could have avoided this, but sometimes straightforward is a good answer.

The intermediate atmac is not needed but is easy to calculate with tr. I'm not sure whether or not all 4 of these variants are needed? Or why atmac is in an array. But I figured that "final mac" was the most important.

Anyway another idea for you...

#!/usr/bin/perl use warnings; use strict; my $mac = '28:8a:1c:59:cc:85'; (my $finalmac = $mac) =~ s/(\w+):(\w+)(:?)/$1$2./g; $finalmac =~ s/.$//; #ditch "." at end (my $atmac = $mac) =~ tr/:/ /; print "mac = $mac\n"; print "atmac = $atmac\n"; print "final mac = $finalmac\n"; __END__ mac = 28:8a:1c:59:cc:85 atmac = 28 8a 1c 59 cc 85 final mac = 288a.1c59.cc85
Update: I just noticed the /o in your regex code. Modern Perl doesn't need this hint. I remember bench marking a lot of stuff years ago with Perl 5.10, and I didn't see any difference. Also see Perl regex documentation 5.22, " o - pretend to optimize your code, but actually introduce bugs". I would pay attention to a cautionary note like that!

In reply to Re: Concatenate and join by Marshall
in thread Concatenate and join by Anonymous Monk

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.