$arrayref = [1, 3, 5, 7]; $hashref = {key1=>val1, key2=>val2, key3=>val3}; #### # want array element - use square brackets $value = $$arrayref[2]; # want hash element - use curly brackets $othervalue = $$hashref{key2}; #### # array of arrays # array - square brackets. Created three times, remember, every reference can be used only once to build another structure. $arrayref1 = [1, 3, 5, 7]; $arrayref2 = [1, 3, 5, 7]; $arrayref3 = [1, 3, 5, 7]; # array of arrays - again: array = square brackets, and it is still only list of scalars, nothing more $array_of_arrays = [$arrayref1, $arrayref2, $arrayref3]; # see how it looks (notice, that Dumper operates only on references. What kind of brackets do you see in the dump?): use Data::Dumper; print Dumper $array_of_arrays; # now: get one element. We have three elements in hmm, lets say, 'outer' level, so the last one will be(array-square brackets): $$array_of_arrays[2]..... # and there are 4 values in 'inner' level, so lets take last one: $value = $$array_of_arrays[2][3]; #### # hash of hashes # hash - curly brackets $hashref1 = {key1 => value1, key2 => value2, key3 => value3, key4 => value4}; $hashref2 = {key1 => value1, key2 => value2, key3 => value3, key4 => value4}; $hashref3 = {key1 => value1, key2 => value2, key3 => value3, key4 => value4}; # hash of hashes, which brackets? :) $hash_of_hashes = {key11 => $hashref1, key22 => $hashref2, key33 => $hashref3}; # see how it looks: use Data::Dumper; print Dumper $hash_of_hashes; # get an element. Nothing surprising, starting from 'outer' level: $$hash_of_hashes{key22}......... # and end with 'inner' key $$hash_of_hashes{key22}{key4}; #### $monk1 = 'Jack'; $monk2 = 'John'; $monk3 = 'Mark'; $monk4 = 'Rudolf'; #order of monks important - using array - square brackets $bank_left1 = [$monk1, '', $monk2]; $bank_left2 = []; $bank_left3 = []; $bank_left4 = []; # order of banks important - use array $left_nave = [$bank_left1, $bank_left2, $bank_left3, $bank_left4]; $bank_right1 = []; $bank_right2 = [$monk3]; $bank_right3 = []; $bank_right4 = []; $right_nave = [$bank_right1, $bank_right2, $bank_right3, $bank_right4]; # existence of elements is important, order not - lets do hash $church = {'left nave'=>$left_nave, 'right nave'=>$right_nave, 'altar'=>1, 'tabernacle'=>1}; # lets declare hash of arrays at once, order of plants not important, but array is here more convenient. # See, instead of (key, value) pairs I use (key, reference-to-array). $garden = {'plants'=>['potato', 'carrot', 'apple tree'], 'monks'=>[$monk4], 'rain'=>1}; # and finally whole monastery, not rich, but its our home :) $monastery = {'church'=>$church, 'garden'=>$garden}; # see how it looks and where monks reside: use Data::Dumper; print Dumper $monastery; #### # using @ in join function $arrayref = $$monastery{'garden'}{'plants'}; print "Plants: ", join ", ", @{$arrayref}; # or @$arrayref # or just # print "Plants: ", join ", ", @{$$monastery{'garden'}{'plants'}}; # using % in keys function $hashref_churchelems = $$monastery{'church'}; print "\nChurch elements: ", join ", ", keys %{$hashref_churchelems}; # or just # print "\nChurch elements: ", join ", ", keys %{$$monastery{'church'}}; print"\n"; # monk sitting in church -> in left nave -> in first bank -> as first print "Monk: ", $$monastery{'church'}{'left nave'}[0][0], "\n";