#! /bin/perl -w # Copyright © 2001-2003 Joe Puliadi. No part # may be reproduced without prior consent. To # get permission, email joe@agatya.com # Name: hoh # URL: /training/bio3/2ndClass/hoh # Author: Joe Puliadi (joe@agatya.com) # Date: Wed Apr 10 15:40:11 PDT 2002 # Syntax: # hoh # # Description: # This program describes how to work with # hash of hashes. # use strict; print "\n"; my %aa_count = ( A => { pos => 3, count => 7 }, B => { pos => 7, count => 1 }, ); # add a new aminoacid to the %aa_count $aa_count{C} = { pos => 4, count => 0 }; # add another aminoacid to %aa_count $aa_count{D}{pos} = 5; $aa_count{D}{count} = 2; # add a new attribute to the aa_count $aa_count{A}{line_no} = 0; $aa_count{B}{line_no} = 1; $aa_count{C}{line_no} = 2; $aa_count{D}{line_no} = 3; print 'Aminoacids of %aa_count: ', join(' ', keys(%aa_count)), "\n"; my @loh = values(%aa_count); print 'Attributes of the aa_count: ', join(' ', keys(%{$loh[0]})), "\n"; # you can access vals with the arrow notation print q/$aa_count{C}->{pos}: /, "$aa_count{C}->{pos}\n"; print "\n"; __END__ Aminoacids of %aa_count: A B C D Attributes of the aa_count: count pos line_no $aa_count{C}->{pos}: 4