c has asked for the wisdom of the Perl Monks concerning the following question:

I am absolutely positive that I have seen this in books as a typical user syntax issue, but I just sold my Cozens book so, I have to turn to the monastery.

My code, is pretty basic

#!/usr/bin/perl -w ## module calls use strict; use Net::SNMP; ## start snmp session my $s = Net::SNMP->session( -hostname => "10.6.21.10", -community => "private" ); ## run the get my $ios_version = $s->get_request(".1.3.6.1.2.1.1.1.0"); my $error = $s->error; ## close the snmp session $s->close; ## print results print "$error\n$ios_version\n\n";

however the output of $ios_version ends up being

HASH(0x811fb50)

i am sure that i have seen this error before, and i had thought it had something to do with trying to represent a hash value as a scalar or vice versa. however, making $ios_version into @ios_version still provides the same output. can someone beat this into my head one more time so it stays?

humbly -c

Replies are listed 'Best First'.
Re: Hash value being called as a Scalar?
by stefp (Vicar) on Oct 08, 2001 at 21:07 UTC
      print "$error\n$ios_version\n\n"; however the output of $ios_version ends up being HASH(0x811fb50)

    The output shows that $ios_version is a reference to hash. Using double quotes is not the proper way to (s)print a composite data structure. One generic way is provided by Data::Dumper.

    use Data::dumper; ... print Dumper $ios_version;

    -- stefp

Re: Hash value being called as a Scalar?
by tune (Curate) on Oct 08, 2001 at 20:59 UTC
    Then $s must be a hash reference. Read more at perlref docs.

    UPDATE: i meant $ios_version :)

    --
    tune

Re: Hash value being called as a Scalar?
by mr_dont (Beadle) on Oct 08, 2001 at 21:04 UTC

    It looks like you are printing a reference, rather than the item being "referenced". Try to access the ios_version by de-referencing the variable using:

    ## print results ## notice the extra "$" in front of the variable print "$error\n$$ios_version\n\n";

    The "$$" provides access to the actual data, rather than the reference, which simply "points" to the location of data

Re: Hash value being called as a Scalar?
by Rex(Wrecks) (Curate) on Oct 08, 2001 at 23:55 UTC
    Now I don't know Net::SNMP and I'm to lazy to look it up :)

    However it looks to me like the key to this problem is finding out what the ->get_request method is expected to return! If you are expecting a scalar then you are having problems, if the method actually returns a hashref then your problem is fairly clear, you need to access the data in a different manner than using it as a simple scalar.

    Use the debugger and set a bp after the ->get_request, then try printing and dumping your var in several different ways until you get what you want, alternatively step through the ->get_request code in the debugger and find out what it is doing.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
Re: Hash value being called as a Scalar?
by converter (Priest) on Oct 09, 2001 at 06:18 UTC

    Read The Fine Manual

    The Net::SNMP manpage clearly states what is returned by the get_request method when called in blocking mode (which is the way you're calling it in your example), and includes helpful examples that illustrate how to use the return value.

    conv