Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Welcome to the Monastery
 
PerlMonks  

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

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 04, 2000 at 21: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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.