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?