Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

(Adam: JoinMapSplit) RE: One for the regexp fans

by Adam (Vicar)
on Aug 04, 2000 at 20:55 UTC ( [id://26229]=note: print w/replies, xml ) Need Help??


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>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://26229]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-28 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found