SPUG: Barewords and Net::SNMP

Jeremy Kahn jeremy_kahn at yahoo.com
Wed Dec 5 15:50:02 CST 2001


--- "Martin, Asa" <asa.martin at attws.com> wrote:
> The Net::SNMP module defines a method called
> set_request, that takes as an
> argument a reference to an array, like this:
> 

> my $sysContact = '1.3.6.1.2.1.1.4.0';
> my $result = $session->set_request(
>    -varbindlist => [$sysContact, OCTET_STRING, 'Help
> Desk x911']
> );

works.
> my $sysContact = '1.3.6.1.2.1.1.4.0';
> my $type = 'OCTET_STRING';
> my $value = 'Help Desk x911';
> my $result = $session->set_request(
>    -varbindlist => [$sysContact, $type, "$value"]
> );

Fails.  Here's why.

OCTET_STRING is actually not a string, it's a
function.

(Reading the code for Net::SNMP suggests that the
function returns 0x04).  You can't use the _string_
'OCTET_STRING' as the argument to set_request, you
have to use the return value of the function of the
same name.

When you use it by reference ($type above), you're
actually passing in the string 'OCTET_STRING', instead
of the return value from the sub &OCTET_STRING, which
is what you get when you don't use singlequotes.

Untested fix to the latter example:

my $sysContact = '1.3.6.1.2.1.1.4.0';
my $type = OCTET_STRING; # removed the single-quotes
my $value = 'Help Desk x911';
my $result = $session->set_request(
   -varbindlist => [$sysContact, $type, "$value"]
);

HTH,

Jeremy


__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/





More information about the spug-list mailing list