[EMAIL PROTECTED] schreef: > I'm currently trying to find a good way to modify a string. A program > returns me a MAC address under the form 0a0a0a0a0a0a, and I would > like to tranform it to obtain : 0a:0a:0a:0a:0a:0a > > I found a such dirty way !! (I think) to do this job : > > my $mac = '0a0a0a0a0a0a'; > my @list; > $list[0] = substr($mac,0,2); > $list[1] = substr($mac,2,2); > $list[2] = substr($mac,4,2); > $list[3] = substr($mac,6,2); > $list[4] = substr($mac,8,2); > $list[5] = substr($mac,10,2); > $toto = join(':',@list); > > I believe there is others ways with regular expressions, by example : > my $mac = '0a0a0a0a0a0a'; > join(':',split(/???/,$mac)); > > where split will return me a list ( '0a','0a','0a','0a','0a' ) > > All my difficulties is to "populate" correctly the delimiter, and to > be honest I begin to have doubt about the fact split is appropriated.
#!/usr/bin/perl use strict ; use warnings ; my $mac = '10203040506' ; # odd length my $toto = $mac ; $toto =~ s/\B(?=(?:[[:xdigit:]]{2})*$)/:/g ; print $toto ; See also this recent thread in c.l.p.moderated: news:[EMAIL PROTECTED] -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>