Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^2: Fetch array of values from hashref (updated)

by AnomalousMonk (Bishop)
on Sep 11, 2019 at 15:36 UTC ( #11106016=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11106016]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2020-09-26 04:24 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (141 votes). Check out past polls.