Feed on
Posts
Comments

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”}};


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

One Response to “how to hash a hash in perl”

  1. on 02 Feb 2008 at 9:09 pm yo

    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!

Did I get this wrong? Let me know!

Trackback URI | Comments RSS