"reverse" returns a list, not a hash; "keys" expects to see something that starts with %. So you could do this to actually dereference an anonymous hash (your version didn't actually make an anonymous hash):


  print keys %{ { reverse %hash } };

Of course you could have just done:

  print values %hash;

(but of course non-unique values would be printed twice).

-Aaron

On Oct 19, 2004, at 9:50 AM, Jason Foster wrote:

Can anyone help me to understand why this code refuses to compile? Even better, can anyone help fix it :)

    %hash = qw( fred filntstone barney rubble tom delong );
    print( keys( reverse( %hash ) ) );

The error message...

Type of arg 1 to keys must be hash (not reverse) at ./killme.pl line 4, near ") ) "

... was pretty confusing since it implies that "reverse" is a type?!

I tried making an anonymous hash as follows...

    print( keys( %{ reverse( %hash ) } ) );

... but got no results at all.

Help!


--
Aaron J. Mackey, Ph.D.
Dept. of Biology, Goddard 212
University of Pennsylvania       email:  [EMAIL PROTECTED]
415 S. University Avenue         office: 215-898-1205
Philadelphia, PA  19104-6017     fax:    215-746-6697



Reply via email to