Hi mick

try this

#!/usr/bin/perl -w
my $mac = '0a0a0a0a0a0a';
$mac=~ s/(..)/$1:/g;
chop($mac);
print $mac;

- Chandru

[EMAIL PROTECTED] wrote:
Hi,

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.

Thanks for help





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to