Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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 (Acolyte) 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2019-10-17 05:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?