how to hash a hash in perl
May 8th, 2007 by Lawrence David
if my loathing of perl was measured in people, that loathing would be china.
for instance, nesting a hash within another hash in perl is needlessly complex: first, you need to stick these dumb backslashes in front of your hash variables:
my %return_vals;
$return_vals{“hgt”} = \%hgt_list;
$return_vals{“dup”} = \%dup_list;
$return_vals{“los”} = \%los_list;
recovering these hashes is similarly unintuitive:
%ref_hgt = %{$ref_list{“hgt”}};
%ref_los = %{$ref_list{“los”}};
%ref_dup = %{$ref_list{“dup”}};
Your mastery of the English language is somewhat wanting.
When you refer to the grammar of a language with the epithet of “dumb,” it kind of tars you with that brush.
We have, many of us, lamented the sigils and the escapes in Perl.
Could you not also do this?
You also call a hash a list here?
and your variables have wierd names.
Here it with refs;
my %hgt_hash;
$hgt_hash{‘key’} = 6;
my $ret_vals = {};
$ret_vals->{‘hgt’} = {%hgt_hash};
#give me something from the underlying hash
my $val = $ret_vals->{‘hgt’}->{‘key’};
should give 6….
or maybe not!