[Columbus-pm] hash of hashes

Chuck Day Chuck.Day at s1te.com
Mon Sep 29 07:08:45 PDT 2008


This is a forum.  We can start here with the basic anonymous hash:

$list = { key1 => value1,
          key2 => value2,
          key3 => value3 };



This is known as %list.



You can add to this:

$list{key4} = value4;




You can print these:

print $list{key4};




Loop through them:

for $key (keys %{ $list } )
{
         do something;
}




I prefer to put the keys into an array though because you can sort these better:

@keys = sort(keys %list);
foreach (@keys)
{
         do something;
}



Sorting it differently:

@keys = sort { $list{$b} cmp $list{$a} } (keys %list);
@keys = sort { $list{$b} <=> $list{$a} } (keys %list);





> Chuck,
>
> Wow could you share these notes in electronic fomat? At times I have issues grasping
> these data structures.
> BTW, will columbus.pm hold a Perl workshop in the spring? I read this on PPW's
> website. I went last year but cannot go this year...scheduling conflicts.
>
>
> thank you
>




More information about the Columbus-pm mailing list