this is a way to get the unique elements of an array:
I would like to do away with the temporary hash and would like to write the following seemingly natural perl-code:my @array = (1,1,2,3,2,2); my %temp = map { $_ => 1 } @array; my @unique = keys %temp;
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".my @unique = keys (map { $_ => 1 } @array);
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.
In reply to keys with an expression by morgon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |