The problem is that values really, really wants the hash to work. This is because it is special: it cleans the seat holder used by each . This requires an actual object.
Here you can go in one of two ways. Firstly, if you don't like ref / deref, you can just pull the temporary hash from the single-line (choose your best code instead of %h ):
my %h = map { $_->{id} => $_->{value} } @obs; say for values %h;
If you don't want %h hang, just put it in a temporary block:
...code code code... { my %h = map { $_->{id} => $_->{value} } @obs; say for values %h; } ...code code code...
Another approach might be to imitate what your temporary hash and values :
my %seen; for ( reverse @obs ) { say $_->{value} unless $seen{$_->{id}}++ }
What really matters is what you are going to do with this data. If you just need your inverted hash values ββonly once, then your single-line scanner might be the best solution. If you need this data (id and value) later, then create the actual hash and use it - do not do this conversion more than once so that you can save them as single-line ones.
Without further context, it is difficult to give advice on which approach to take.
source share