I was slurping an internal web page that contains MAC addresses as a 12 char hexadecimal string, e.g. 01fe9d8d68e7.
I wanted to format these strings in a more conventional representation, e.g. 01:fe:9d:8d:68:e7. And when I wrote this snippet, it worked perfectly the first time!
I don't think I could have written this 4 years ago. Reading Perlmonks all this time has improved my Perl immeasurably. So, thanks.
# $mac = '01fe9d8d68e7'; $mac = join( ':' => ($mac =~ /(..)/g) );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Use of the m/.../g idiom in list context (formatting MAC addresses)
by uksza (Canon) on Jan 17, 2005 at 13:22 UTC | |
by grinder (Bishop) on Jan 17, 2005 at 14:36 UTC | |
by merlyn (Sage) on Jan 17, 2005 at 17:28 UTC | |
by tye (Sage) on Jan 17, 2005 at 20:12 UTC | |
Re: Use of the m/.../g idiom in list context (formatting MAC addresses)
by eyepopslikeamosquito (Archbishop) on Jan 18, 2005 at 06:47 UTC |
Back to
Cool Uses for Perl