|Pathologically Eclectic Rubbish Lister|
Re: Hash slice from a hashref, into a hashrefby haukex (Bishop)
|on Apr 25, 2018 at 17:42 UTC||Need Help??|
I just realized the question is useless.
I'm not sure why you think so, how to take a slice of a hash is a valid question, maybe you could explain what resolution you found for your question?
Anyway, there are several ways to make a (shallow) copy of a part of a hash, here are a few:
my %h is really big and I don't have enough RAM to make a copy of it
This makes the question interesting. It turns out that, at least on my machine with Perl 5.26, from the options above:
I want to load the slice directly into a hashref
As it turns out, changing my %slice into my $slice and changing the syntaxes into the following doesn't really make a big difference:
On the other hand, if for example the values in your hash are huge, then perhaps a different approach is needed - for example, in your second hash you could store references to the values of the first hash. Or, you may not even need to create a second hash in the first place, perhaps simply keeping the list of keys around to select values from the first hash is enough.