I'm using Net::ARP to do an ARP lookup (using arp_lookup() from the module). For some (unknown to me) reason, when I store IP addresses as keys in a hash before handing them to arp_lookup(), they will not work unless I first assign the key to another variable. I can then use the original hash key in arp_lookup(). It seems odd to me; I've not run into this situation before. I thought at first the module might have Taint checking on, but that does not appear to be the case.

I coded up a simple example demonstrating the (again, to me) oddity. I hope it's just something I'm doing incorrectly. :)

Thank you for any insight into what is happening here.
Casey

UPDATE: I removed the $ipaddr2 assignment I mentioned. Really, any access to the $ipaddr variable between the first arp_lookup() call and second arp_lookup() call will cause the second call to work. So, the print after the first arp_lookup() fills the access role. Thank you, japhy for helping me simplify the example.

Example:
#!/usr/bin/perl use warnings; use strict; use Net::ARP; my $device = q{eth0}; my %ipaddrs = ( q{192.168.1.100} => q{} ); for my $ipaddr (sort keys %ipaddrs) { my $mac = q{}; Net::ARP::arp_lookup($device, $ipaddr, $mac); print qq{$ipaddr : $mac\n}; Net::ARP::arp_lookup($device, $ipaddr, $mac); print qq{$ipaddr : $mac\n}; }

Example Output
192.168.1.100 : 192.168.1.100 : 01:41:02:8F:70:80

In reply to Of Net::Arp and Hashes by cmilfo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.