http://www.perlmonks.org?node_id=1063494

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

Hi

this is a way to get the unique elements of an array:

my @array = (1,1,2,3,2,2); my %temp = map { $_ => 1 } @array; my @unique = keys %temp;
I would like to do away with the temporary hash and would like to write the following seemingly natural perl-code:

my @unique = keys (map { $_ => 1 } @array);
But to my amazement this does not work with 5.18.1 - the error is "Type of argument to keys on reference must be unblessed hashref or arrayref".

I could swear this used to work some years ago (not really sure), so my question is how can I do this - how can I use keys with such an expression?

Is there really no way to avoid the ugly temporary?

Please note that the above is just an illustration - this is not a question about how to find unique array elements but a question concerning the kinds of expressions I can feed into keys.