Ravendark has asked for the wisdom of the Perl Monks concerning the following question:
each one of them having 60 sections (which represent 60 ports of a machine.) and I have a piece of code that takes an ifindex and stores the values of slot & port into two separate arrays.[2287] slot = 20 port = 1
every time I run it I get this: Can't call method "val" on an undefined value at /home/portal/bin/snmp_set.pl line 142. and line 142 is: $slot = $cfg->val("$ifindex[$t]", "slot"); in the last if statement. If I comment out this section, the program runs without problem. Thanks in advance.sub translate_ifindex() { my $ports_ini_dir = "/home/portal/bin/conf/snmp_set"; my $slot; my $port; for ($t = 0; $t < @ifindex; $t++) { #print "IFINDEX: $ifindex[$t]\n"; if ($ifindex[$t] >= 204 && $ifindex[$t] <= 381) { my $cfg = new Config::IniFiles( -file => "$ports_ini_dir/s +nmp_ports_slot02.txt" ); $slot = $cfg->val("$ifindex[$t]", "slot"); $port = $cfg->val("$ifindex[$t]", "port"); push @msan_slot, $slot; push @msan_port, $port; } if ($ifindex[$t] >= 22 && $ifindex[$t] <= 199) { my $cfg = new Config::IniFiles( -file => "$ports_ini_dir/s +nmp_ports_slot04.txt" ); $slot = $cfg->val("$ifindex[$t]", "slot"); $port = $cfg->val("$ifindex[$t]", "port"); push @msan_slot, $slot; push @msan_port, $port; } if ($ifindex[$t] >= 513 && $ifindex[$t] <= 690) { my $cfg = new Config::IniFiles( -file => "$ports_ini_dir/s +nmp_ports_slot06.txt" ); $slot = $cfg->val("$ifindex[$t]", "slot"); $port = $cfg->val("$ifindex[$t]", "port"); push @msan_slot, $slot; push @msan_port, $port; } if ($ifindex[$t] >= 823 && $ifindex[$t] <= 1000) { my $cfg = new Config::IniFiles( -file => "$ports_ini_dir/s +nmp_ports_slot08.txt" ); $slot = $cfg->val("$ifindex[$t]", "slot"); $port = $cfg->val("$ifindex[$t]", "port"); push @msan_slot, $slot; push @msan_port, $port; } if ($ifindex[$t] >= 1067 && $ifindex[$t] <= 1244) { my $cfg = new Config::IniFiles( -file => "$ports_ini_dir/s +nmp_ports_slot10.txt" ); $slot = $cfg->val("$ifindex[$t]", "slot"); $port = $cfg->val("$ifindex[$t]", "port"); push @msan_slot, $slot; push @msan_port, $port; } if ($ifindex[$t] >= 1311 && $ifindex[$t] <= 1488) { my $cfg = new Config::IniFiles( -file => "$ports_ini_dir/s +nmp_ports_slot12.txt" ); $slot = $cfg->val("$ifindex[$t]", "slot"); $port = $cfg->val("$ifindex[$t]", "port"); push @msan_slot, $slot; push @msan_port, $port; } if ($ifindex[$t] >= 1555 && $ifindex[$t] <= 1732) { my $cfg = new Config::IniFiles( -file => "$ports_ini_dir/s +nmp_ports_slot14.txt" ); $slot = $cfg->val("$ifindex[$t]", "slot"); $port = $cfg->val("$ifindex[$t]", "port"); push @msan_slot, $slot; push @msan_port, $port; } if ($ifindex[$t] >= 1799 && $ifindex[$t] <= 1976) { my $cfg = new Config::IniFiles( -file => "$ports_ini_dir/s +nmp_ports_slot16.txt" ); $slot = $cfg->val("$ifindex[$t]", "slot"); $port = $cfg->val("$ifindex[$t]", "port"); push @msan_slot, $slot; push @msan_port, $port; } if ($ifindex[$t] >= 2043 && $ifindex[$t] <= 2220) { my $cfg = new Config::IniFiles( -file => "$ports_ini_dir/s +nmp_ports_slot18.txt" ); $slot = $cfg->val("$ifindex[$t]", "slot"); $port = $cfg->val("$ifindex[$t]", "port"); push @msan_slot, $slot; push @msan_port, $port; } if ($ifindex[$t] >= 2287 && $ifindex[$t] <= 2464) { my $cfg = new Config::IniFiles( -file => "$ports_ini_dir/s +nmp_ports_slot20.txt" ); $slot = $cfg->val("$ifindex[$t]", "slot"); $port = $cfg->val("$ifindex[$t]", "port"); push @msan_slot, $slot; push @msan_port, $port; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Undefined value
by wfsp (Abbot) on Jun 19, 2009 at 12:21 UTC | |
|
Re: Undefined value
by wfsp (Abbot) on Jun 19, 2009 at 13:13 UTC | |
|
Re: Undefined value
by Anonymous Monk on Jun 19, 2009 at 12:21 UTC | |
by Anonymous Monk on Jun 19, 2009 at 12:41 UTC | |
by Ravendark (Acolyte) on Jun 19, 2009 at 12:44 UTC | |
by Anonymous Monk on Jun 19, 2009 at 12:48 UTC |