Re: Dynamically creating a hash for keys()

[email protected] (Georg Moritz)
Newsgroups perl.fwp
Message-ID <[email protected]>
From the keyboard of Jason Foster [19.10.04,09:50]:

> 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 ) } ) );

wrong brackets ;-)

print keys %{{reverse @{[%hash]}}}

coerce the hash into an anonymous array, deref it, reverse the
resulting list, put it into an anonymous hash, get keys from the ref

-gg-

> ... but got no results at all.
>
> Help!
>
>

-- 
_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s,/,($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e,e && print}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.