Jason Foster <[EMAIL PROTECTED]> wrote:
This is probably not the place for these kind of questions, but here
goes anyway.
> 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?!
>
The implication was meant to just indicate what you were saying instead
of what perl was expecting. reverse is not a type :)
But the type of what reverse returns is a list, not a hash. I wondered
about this once too. Your attempt at a solution:
> print( keys( %{ reverse( %hash ) } ) );
>
was almost right, but not quite. You can't dereference a list, but you
can deref a reference to an anonymous hash:
print keys %{ { reverse %hash } };
Note, by the way, that if you know your data contains no duplicate
values, you could simply have done this:
print values %hash;
--
Gaal Yahas <[EMAIL PROTECTED]>
http://gaal.livejournal.com/