Fellow monks, I would like to ask for help.

I am using Net::SNMP to pull an OID value. I am getting the value, but it is matching both conditions and I am not sure why.

#!c:/perl/perl.exe use Net::SNMP; use Data::Dumper; my $on_battery = "5"; #Indicates that the UPS in on battery power my $on_commercial = "3"; #Indicates that the UPS in on commercial p +ower # requires a hostname and a community string as its arguments ($session,$error) = Net::SNMP->session(Hostname => "test_ups", Communi +ty => "public"); die "session error: $error" unless ($session); #.1.3.6.1.2.1.33.1.4.1 is the OID the battery status of the UPS my $result = $session->get_table (".1.3.6.1.2.1.33.1.4.1"); die "request error: ".$session->error unless (defined $result); print Dumper( $result ); my @values = values (%$result); foreach my $key (@values) { print "$key\n"; my $status = $key; print "$status\n"; } if ( $status = $on_commercial ) { print "The ups is normal\n"; } if ( my $status = $on_battery ) { print "The ups is on battery\n"; } $session->close;
Here is the output I am getting
C:\>snmp.pl $VAR1 = { '.1.3.6.1.2.1.33.1.4.1.0' => 3 }; 3 3 The ups is normal The ups is on battery
I am sure that it is some newbie syntax error.
I changed so "$status == $on_commercial" and added warnings.. now I get
$VAR1 = { '.1.3.6.1.2.1.33.1.4.1.0' => 3 }; 3 3 Use of uninitialized value in numeric eq (==) at C:\SNMP.p l line 25. Use of uninitialized value in numeric eq (==) at C:\SNMP.p l line 29.
How is it uninitialized when I defined the variables?
Thanks everyone for helping out a newbie.
Thanks,
JB

In reply to Multiple conditions matching when pulling OID value with Net::SNMP by Bennco99

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.