in reply to Insert colons into a MAC address
but I would prefer a regex
Any particular reason? If you're thinking of input validation, how about:
$_ = '525400eb8b36'; die "Invalid input\n" if length != 12 or /[^[:xdigit:]]/; print join ':', unpack '(A2)*';
Alternatively, use a CPAN module:
use Net::MAC; print Net::MAC->new( mac => '525400eb8b36' )->as_Sun();
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Insert colons into a MAC address
by xyzzy (Pilgrim) on Jan 14, 2012 at 09:13 UTC | |
by mantager (Sexton) on Jan 14, 2012 at 22:44 UTC |
In Section
Seekers of Perl Wisdom