Currently I am pushing certain values into an array, but I think my goal would be best accomplished by populating a hash with values from another hash and a `back-tick` command.
The first hash is a Value=>Label which I loop over pushing "Label" into another hash as the key and passing the "Value" to a back-tick command, to be used as the associated keys value. I hope that makes sense. ;)
Here is a snippet of where I am at:
$direction = shift;
%iface = (
"if${direction}Octets.2" => 'FastEthernet0/1',
"if${direction}Octets.3" => 'FastEthernet0/2',
"if${direction}Octets.4" => 'FastEthernet0/3',
"if${direction}Octets.5" => 'FastEthernet0/4',
"if${direction}Octets.26" => 'GigabitEthernet0/1',
);
foreach my $oid (sort keys(%iface)) {
%oids = ("$iface{$oid}" => `$snmpwalk $ip $community $oid`);
}
The %oids hash seems to be overwriten with each loop, leading me to re-think the process. I was previously pushing the above data onto an array, but I need to keep the label and 'return values' together for later pushing into a db.
I was thinking of another variation on the loop, something like:
foreach my $oid (sort keys(%iface)) {
@oids = ({"$iface{$oid}" => `$snmpwalk $ip $community $oid`});
}
However, I am not exactly sure how to get the data pairs back out of the @oids array. Can anyone nudge me in the right direction?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.