Find the answer to your Linux question:
Results 1 to 3 of 3
I have a problem with a hash reference. ... my $GetMsgDesc = {}; ... my $Buffer = MQGET($HConn, $HobjIP, $GetMsgDesc, $GetMsgOpts, $BufferLength, $CompCode, $Reason); print $GetMsgDesc, "\n"; ... which print ...
  1. #1
    Linux Newbie
    Join Date
    Dec 2008
    Location
    Luxembourg
    Posts
    130

    Perl : hash reference values

    I have a problem with a hash reference.

    ...
    my $GetMsgDesc = {};
    ...
    my $Buffer = MQGET($HConn, $HobjIP, $GetMsgDesc, $GetMsgOpts, $BufferLength, $CompCode, $Reason);

    print $GetMsgDesc, "\n";
    ...

    which print 'HASH(0x36d560)'

    My question : from here how to print keys and values stored in $GetMesgDesc ?


    Thanks for help.
    Bye,
    Bruno

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    You have to dereference the hashref. You can do this in one of two ways:

    1) To get the hash that is being referenced, you simply do %$GetMsgDesc

    2) To get a value for a key in the hash that is being referenced, you do $GetMsgDesc->{$key}

    I hope that helps.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Linux Newbie
    Join Date
    Dec 2008
    Location
    Luxembourg
    Posts
    130
    Thanks Cabhan.
    Indeed it helps.

    Bye,
    Bruno

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...