http://qs1969.pair.com?node_id=26229


in reply to One for the regexp fans

$mac = join '', map { /^([0-9a-f])$/i ? "0$1" : $_ } split /\./, $addr +;
The nice thing about perl is that it allows you to code in a manner that simulates speech. You said something like, "I want to split up the address at the dots, prefix zeros to single digit hex values, and join it all together to make a value." Which, incidentally, is exactly what the above one-liner does.

Replies are listed 'Best First'.
RE: (Adam: JoinMapSplit) RE: One for the regexp fans
by Anonymous Monk on Aug 05, 2000 at 01:44 UTC
    How about using sprinf: $mac = join "", map {sprintf "%02s", $_} split '\.', $addr
      Forgot to put CODE tags, so I am replying to myself.

      <CODE>$mac = join "", map {sprintf "%02s", $_} split '\.', $addr<CODE>

      Forgot to put CODE tags, so I am replying to myself. <CODE>$mac = join "", map {sprintf "%02s", $_} split '\.', $addr<CODE>