> @$foo{bar}

What you intend by the above is the scalar value
in $foo{bar} dereferenced as an array by the @.

But that's not what happens. To achieve what you
want, use:

    @{$foo{bar}}

The issue here is precedence of sigils (@, $, etc.)
versus subscript parens ({}, []), and the meaning
of various combinations of sigils and subscripts.

Sigils have a higher precedence than subscripts.
To force the meaning you wanted, we, well,
forced the meaning you wanted.

Fwiw, @$foo{bar} specifies that you want a list,
consisting of the values corresponding to the list
of keys in the parens (in this case a list of length
1, namely bar), looked up in the hash referenced
by $foo.

So, this should work:

    %h = (key=>'value', key2=>'value2');
    $foo = \%h;
    print @$foo{key, key2};

hth.

Reply via email to