in reply to Undefined value
Untested due to not having the config files.#! /usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 2; my @ranges = ( # low high conf_file [ 204, 381, 2], [ 22, 199, 4], [ 513, 690, 6], [ 823, 1000, 8], [1067, 1244, 10], [1311, 1488, 12], [1555, 1732, 14], [1799, 1976, 16], [2043, 2220, 18], [2287, 2464, 20], ); my %lookup; for my $range (@ranges){ my ($low, $high, $slot) = @{$range}; for my $index ($low..$high){ $lookup{$index} = $slot; } } #print Dumper \%lookup; #exit; my @ifindex = (204, 22, 513); my ($msan_slot, $msan_port) = translate_ifindex(@ifindex); sub translate_ifindex { my @ifindex = @_; my $ports_ini_dir = "/home/portal/bin/conf/snmp_set"; my (@msan_slot, @msan_port); for my $t (0..$#ifindex) { if (exists $lookup{$t}){ my $cnf_file = sprintf(q{%s/snmp_ports_slot%02d.txt}, $ports_ini +_dir, $lookup{$t}); my $cfg = Config::IniFiles->new( -file => $cnf_file) or die q{cant open *$cnf_file*}; my $slot = $cfg->val($ifindex[$t], "slot"); my $port = $cfg->val($ifindex[$t], "port"); push @msan_slot, $slot; push @msan_port, $port; } } return \@msan_slot, \@msan_port; }
updated: corrected table syntax and sprintf format string
|
|---|