Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by Adam (Vicar)
on Aug 04, 2000 at 20:55 UTC ( #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.


Comment on (Adam: JoinMapSplit) RE: One for the regexp fans
Download Code
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
Node Status?
node history
Node Type: note [id://26229]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-10-02 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (52 votes), past polls