http://www.perlmonks.org?node_id=1159211


in reply to Concatenate and join

Given MAC-48 format, using either colons or hyphens, how about a substitution:
$ perl -le '$re = qr{(\S\S)[-:](\S\S)[-:](\S\S)[-:](\S\S)[-:](\S\S)[-: +](\S\S)}; $str1 = "28:8a:1c:59:cc:85"; $str2 = "28-8a-1c-59-cc-85"; ( $cat1 = $str1 ) =~ s/$re/$1$2.$3$4.$5$6/; ( $cat2 = $str2 ) =~ s/$re/$1$2.$3$4.$5$6/; print "$str1 is now $cat1\n"; print "$str2 is now $cat2\n"; ' __output__ 28:8a:1c:59:cc:85 is now 288a.1c59.cc85 28-8a-1c-59-cc-85 is now 288a.1c59.cc85
Too ugly??

Replies are listed 'Best First'.
Re^2: Concatenate and join
by AnomalousMonk (Chancellor) on Mar 31, 2016 at 20:55 UTC

    Dunno if this is too/more/less ugly, but anyway...
    File: convert_mac_addr_2.pl

    Output:


    Give a man a fish:  <%-{-{-{-<