Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Concatenate and join

by dbuckhal (Friar)
on Mar 31, 2016 at 16:36 UTC ( #1159211=note: print w/replies, xml ) Need Help??


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:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1159211]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2018-10-17 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (92 votes). Check out past polls.

    Notices?