Header RSS Feed
If you only want to see the articles of a certain category, please click on the desired category below:
ALL Android Backup BSD Database Hacks Hardware Internet Linux Mail MySQL Monitoring Network Personal PHP Proxy Shell Solaris Unix Virtualization VMware Windows Wyse

Use of uninitialized value XXX in concatenation (.) or string (perl snmp)
Thursday - Jun 26th 2014 - by - (0 comments)

While I was working on a Perl script which uses Net::SNMP, I got the following error:

Need to query .
Odd number of elements in hash assignment at /usr/lib/perl5/vendor_perl/5.16.2/Net/SNMP.pm line 2278.
Use of uninitialized value $enclosure in concatenation (.) or string at ./myscriptpl line 288.

What I was doing in my perl script was this:

      print "Need to query $oid_base.$oidend\n"; # debug
      my @oidlist2 = ($oid_base.$oidend);
      my $response = $session->get_request(-varbindlist => \@oidlist2);
      my $enclosure = $$response{"$oid_base.$oidend"};

Now the issue is that I missed the fact that I can't just put multiple variables together like this. It works correctly in the "print" line, because there I have set everything as a string in double-quotes.
In the definition of oidlist2, I forgot to use the double-quotes - so the OID wasn't really a SNMP OID anymore, which caused the snmp request to fail.

Ti simply put the oidlist2 definition into double-quotes solved that issue:

      #print "Need to query $oid_base.$oidend\n"; # debug
      my @oidlist2 = ("$oid_base.$oidend");
      my $response = $session->get_request(-varbindlist => \@oidlist2);
      my $enclosure = $$response{"$oid_base.$oidend"};
      #print "This drive is in Enclosure: $enclosure\n"; # debug

On my research "perl snmp Use of uninitialized value in concatenation" I did not find a single website pointing me to the solution. So once I figured it out myself, I thought I'd share that.


Add a comment

Show form to leave a comment

Comments (newest first):

No comments yet.

Go to Homepage home
Linux Howtos how to's
Monitoring Plugins monitoring plugins
Links links

Valid HTML 4.01 Transitional
Valid CSS!
[Valid RSS]

6939 Days
until Death of Computers