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

Hello perl monks,
I have a variable $res, which hold the following content when I print it out with Dumper($res).

$VAR1 = bless( { 'key1' => 'abc', 'key2' => '0' }, 'my_obj' );
How can I print the value of of 'key2', which is 0? Thanks!

Replies are listed 'Best First'.
Re: how to print values?
by blue_cowdawg (Monsignor) on Sep 15, 2011 at 19:03 UTC
        How can I print the value of of 'key2', which is 0? Thanks!

    I had to read this three or four times before I was convinced this was not a trick question...

    printf "%d\n",$VAR->{key2};

    Or am I missing something here?


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
      Maybe he's confused by the bless? bless simply adds an annotation the referenced hash, then returns the reference passed to it. So one still ends up with a hash reference in the OP's example.
Re: how to print values?
by SuicideJunkie (Vicar) on Sep 15, 2011 at 19:11 UTC
    See perlreftut

    $res = {foo=>bar}; # a hash ref $res-> # de-reference and then... {foo}; # ...look up a key in the hash