Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Help me decipher code containing map function

by AnomalousMonk (Archbishop)
on May 20, 2017 at 04:54 UTC ( [id://1190695]=note: print w/replies, xml ) Need Help??


in reply to Help me decipher code containing map function

What BrowserUk said. And if for some reason you really want the address in two-byte groups:

c:\@Work\Perl\monks>perl -wMstrict -le "my $octetstr = qq{\xab\xcd\x00\x1d\x94\x56}; ;; my $mac = join '.', unpack '(H4)*', $octetstr; print qq{'$mac'}; " 'abcd.001d.9456'

Update:

Why do i get an error when I start my code like "map { my $val .=" instead of declaring $val separately.
Because if your code were
    map { my $val .= sprintf("%02x",$_) } unpack "CCCCCC", $octetstr;
    $mac=join(".",unpack("a4 a4 a4",$val));
then the  $val lexical scoped within the map block is entirely local to the map block and does not exist outside of it, so the  $val variable in the
    $mac=join(...,unpack(...,$val));
statement is undeclared and is a syntactic error under strict (if that's the error you're getting) — unless you have an unrelated  $val declared somewhere, which would be a semantic error.


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: Help me decipher code containing map function
by adamZ88 (Beadle) on May 23, 2017 at 14:36 UTC

    Thank you for showing me how to unpack the MAC in additional ways Anomalous, this is very helpful in the networking world!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-11-14 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    chatterbot is...






    Results (39 votes). Check out past polls.