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


in reply to Re: Fetch array of values from hashref
in thread Fetch array of values from hashref

... for your problem ...

I would go a bit further than haukex and say that the problem exemplified in the OP is to extract the values of a subset | an ordered subset of hash keys, whereas  values %$h gives you the values of all keys (in random order!). Again, not an equivalent solution.

Update: As a side note, WRT hash key/value ordering it's worth mentioning that keys, values, and each all state that:

So long as a given hash is unmodified you may rely on keys, values and each to repeatedly return the same order as each other. See Algorithmic Complexity Attacks in perlsec for details on why hash order is randomized.
The actual random ordering will differ from one run of a script to another if this security feature is enabled. (IIRC, this feature, enabled by default, can be disabled during the build of a Perl interpreter.)


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: Fetch array of values from hashref
by k-mx (Scribe) on Sep 11, 2019 at 16:30 UTC

    Yes, my bad. I thought he needed all values.

    P.S. I want to share another cool hack, maybe somebody don't know about it:

    ( \$Param{Foo}, \$Param{Bar} ); \( $Param{Foo}, $Param{Bar} ); \@Param{'Foo', 'Bar'};
    You can use it in situations like this