I have rewritten your code to make it a bit Perl like. The following code is equivalent to your code -
use strict; use Data::Dumper; my $network_ifs = `netstat -i | grep -Ev "lo|sit|link|Name" | cut -f1 +-d" " | uniq | sort -n`; my @tcp_utilization_metrics = split '\n', $network_ifs; my %tcp_utilization_adapter_names; foreach my $network_if (@tcp_utilization_metrics) { next if ! $network_if; # ignore empty lines if any my $if_name = $network_if; if ($network_if =~ /en/) { substr($network_if, 2, 0) = "t"; # insert 't' } elsif ($network_if =~ /tr/) { substr($network_if, 1, 2) = "ok"; # replace 'ok' } elsif ($network_if =~ /at/) { substr($network_if, 2, 0) = "m"; # insert 'm' } # insert hash entries $tcp_utilization_adapter_names{$if_name} = $network_if; } # investigate the hash foreach (keys %tcp_utilization_adapter_names) { print "$tcp_utilization_adapter_names{$_}\n"; }
Perhaps you could tell us what is your expected hash output. I highly suspect that you want the following instead in your code (swap the key-value in the hash) -
# insert hash entries $tcp_utilization_adapter_names{$network_if} = $if_name;

In reply to Re: Re: Re: Simple hash assignment...or is it? by Roger
in thread Simple hash assignment...or is it? by arootbeer

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.