On Tue, Sep 29, 2009 at 07:40, Jeff Peng <jeff.p...@freenet.de> wrote: > 2009/9/29 Shawn H Corey <shawnhco...@gmail.com>: >> Soham Das wrote: >>> >>> How can I create a Hash of Hashes from two lists. Is it possible? >>> >>> I want the effective functionality to be served like this >>> >>> $ChildHash["Joe"]["21A"]="Sally" >>> >>> i.e Joe at 21A has a child called Sally. List1 here will be the name of >>> Parents, List2 here will contain the house number. >> >> Hashes use {}, arrays use [] >> > > > That's in Python? :-) > Perl's both hash and array use (). > But anonymous hash and array use {} and []. snip
To clarfy, Perl uses (LIST) to initialize hashs and arrays. One way to create a list is (X). my @a = (1, 2, 3); my %h = (a => 1, b => 2, c => 3); Perl uses X[Y] to get the value at the Yth index in X when X is an array or a list. my $x = $a[1]; #$x is now 2 Perl uses X{Y} to get the value associated with Y when X is a hash. $x = $h{c}; #$x is now 3 Perl uses [LIST] to create an anonymous array ref. my $aref = [1, 2, 3]; $x = $aref->[0]; #$x is now 1 Perl uses {LIST} to create an anonymous hash ref. my $href = {a => 1, b => 2, c => 3}; $x = $href->{b}; #$x is now 2 See [perldoc perlop][1] or my [perlopref][2] document for more information. [1] : http://perldoc.perl.org/functions/perlop.html [2] : http://github.com/cowens/perlopref -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/