Good explanation, but the conclusion is backwards. Line 10 and 28 are correct; it's line 5 that's wrong. There are multiple nics, so there should be multiple hashes. The real problem is that the function pretends there's only one. It should be returning a list of nics (list of hashes).

sub networkInfo { my @nics; my $platform = getPlatform(); if ($platform =~ /RedHat/) { my $ifconfig = qx|/sbin/ifconfig| or die("Can't get info from Linux ifconfig: $!\n"); for (split /(?<=\n)(?=\w)/, $ifconfig) { my %nic; ($nic{device}) = /^(eth\d)\s/ or next; if (/\binet addr:([\d.]+)\s.+?:([\d.]+)\s.+?:([\d.]+)/) { $nic{ip} = $1; $nic{bcast} = $2; $nic{mask} = $3; } if (/^\s+ inet6 addr:\s*(\S+)/m) { $nic{ip6} = $1; } push @nics, \%nic; } } elsif ($platform =~ /SunOS/) { my $ifconfig = qx|/sbin/ifconfig -a| or die("Can't get info from Solaris ifconfig: $!\n"); for (split /(?<=\n)(?=\w)/, $ifconfig) { my %nic; ($nic{device}) = /^(fjgi\d)\s/ or next; if (/\binet addr:([\d.]+)\s.+?:([\d.]+)\s.+?:([\d.]+)/) { $nic{ip} = $1; $nic{bcast} = $2; $nic{mask} = $3; } if (/^\s+ inet6 addr:\s*(\S+)/m) { $nic{ip6} = $1; } push @nics, \%nic; } } return @nics; } for my $nic (networkInfo()) { print(join( "\t", map $_//'[undef]', @{$nic}{qw( device ip ipv6 bcast mask )} ), "\n"); }

Update: Cleaned up opening paragraph.
Update: Second push discovered ability to turn invisible. Added anti-invisibility field to post so it's visible again.


In reply to Re^2: Data::Dumper is returning empty by ikegami
in thread Data::Dumper is returning empty by MikeDexter

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.