Hi all, I have an array of 600 elements (indices of interfaces) and 10 ini-style files. each ini-style file has the form:
[2287] slot = 20 port = 1
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.
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; } } }
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.

In reply to Undefined value by Ravendark

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.