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

I'm teaching myself references.

programming perl page 246 has:

$hashrefA = {
'Adam' =>'Eve',
'Clyde'=>$bonnie,
'Antony' =>'Cleo' . 'patra'
};

I'm trying to print Eve but can't figure it out.

$a1 = $hashrefA->'Adam';

print "a1 = $a1\n";


I've tried many combinations.

Help?

Replies are listed 'Best First'.
Re: pg 246 of programming perl
by prasadbabu (Prior) on Jun 28, 2005 at 05:24 UTC

    Change it into,

    $a1 = $hashrefA->{'Adam'};

    Now you will be getting the correct output.

    Prasad

      Correct!,
      Since you want to 'learn references', what prasadbabu did, was dereferencing, so $a1 actually holds it's own copy of the value derederendec from the hash.

      "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
Re: pg 246 of programming perl
by GrandFather (Saint) on Jun 28, 2005 at 05:46 UTC

    Or even:

    print "$$hashrefA{Adam}\n";

    Perl is Huffman encoded by design.
Re: pg 246 of programming perl
by tlm (Prior) on Jun 28, 2005 at 10:35 UTC