Hi All,
I have a piece of code that was given to me in class about 4 years ago. I am now starting to use the code heavily. I can simply copy and paste the code into any script requiring it, but I would rather know step by step exactly what the code is doing so that I am better informed to adjust it to other situations. Please let me know if the code is omitting anything that might be considered as default
I am using SNMP to retrieve the ARP table of a Cisco switch. The response is a mac address that comes back packed, so I must unpack it to present it in a human friendly manner.
The end result ends up being something like: abcd.001d.9456. The piece of code is this:
my $val; map { $val .= sprintf("%02x",$_) } unpack "CCCCCC", $octetstr; $mac=join(".",unpack("a4 a4 a4",$val));
Now, before you tell me to go and do some reading, I have. I am coming to you because I still have some doubts.I.E: I thought that the map function takes in a list(perhaps an array), I do not see the above code having a list passed to it. Unless the packed mac address contained in $octetstr is the list. I am also not quite sure what sprintf("%02x",$_) is ll about. Why is this needed? For better readability of the code, how can I rename the $_ variable. Why do i get an error when I start my code like "map { my $val .=" instead of declaring $val separately. Thank you.
In reply to Help me decipher code containing map function by adamZ88
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |