shagbark has asked for the wisdom of the Perl Monks concerning the following question:
ARGH. I want to delete this node; I just realized the question is useless. But I can't figure out how to delete it.
But I want to load the slice directly into a hashref, not a hash, because my %h is really big and I don't have enough RAM to make a copy of it. I want to do what you might think this would do:use strict; use warnings; my %h=(a=>1,b=>2,c=>3); my @x=('a','c'); my $hr=\%h; my %g=%$hr{@x}; # plain old %g = %h{@x} also works my $gr = \%g; print $gr->{a} # prints "1" print $gr->{b} # prints "Use of uninitialized value in print"
Or maybe one of these:my %h=(a=>1,b=>2,c=>3); my @x=('a','c'); my $hr = \%h; my $gr = $hr->{@x}; print $gr->{a}
Alas, none of these work. Is there a way to get a slice of a hash (not of its values, but of the hash) without making a copy of the hash? Preferably from a hashref to the original hash, since that's what I've got.my $gr = $hr{@x}; my $gr = $$hr->{@x}; my $gr = \%{$hr}{@x}
I asked a question, then realized that there was no point in asking what I was asking.
So I have deleted it.
Perlmonks.org does not allow deletion of nodes, so here we are.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: This is a useless node
by Marshall (Canon) on Apr 25, 2018 at 05:01 UTC | |
by mxb (Pilgrim) on Apr 25, 2018 at 09:09 UTC | |
Re: Hash slice from a hashref, into a hashref
by haukex (Archbishop) on Apr 25, 2018 at 17:42 UTC | |
Re: This is a useless node
by Your Mother (Archbishop) on Apr 25, 2018 at 04:56 UTC | |
Re: This is a useless node
by haukex (Archbishop) on Apr 25, 2018 at 09:13 UTC | |
Re: This is a useless node
by virtualsue (Vicar) on Apr 25, 2018 at 11:08 UTC | |
by Anonymous Monk on Apr 25, 2018 at 12:23 UTC | |
by Anonymous Monk on Apr 25, 2018 at 17:01 UTC | |
by virtualsue (Vicar) on Apr 26, 2018 at 19:04 UTC | |
by Your Mother (Archbishop) on Apr 27, 2018 at 00:10 UTC | |
by Anonymous Monk on Apr 26, 2018 at 20:23 UTC |