Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Concatenate and join

by dbuckhal (Chaplain)
on Mar 31, 2016 at 16:36 UTC ( [id://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 (Archbishop) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1159211]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-19 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found