[Appendix B] B.2 Nested Data Structures
Author: Sriram Srinivasan
Date: 1999-07-02T01:43:16Z

#

| Appendix B Syntax Summary |

## B.2 Nested Data Structures

Each array or hash is a collection of scalars, some or all of which can be references to other structures.

7. Lists do not nest like this:

       @foo = (1, 3, ("hello", 5), 5.66);

   For nesting, make the third element a reference to an anonymous array:

       @foo = (1, 3, ["hello", 5], 5.66);

8. An example of a nested data structure (a hash of array of hashes):

       $person = {   # Anon. hash
          "name" => "John",  # '=>' is an alias for a comma
          "age"  => 23,
          "children" => [  # Anonymous array of children
                            {
                               "name" => "Mike",  "age"  => 3,
                            },
                            {
                               "name"  => "Patty","age"   => 4
                            }
                        ]
          };
       print $person->{age}                 ; # Print John's age
       print $person->{children}->[0]->{age}; # Print Mike's age
       print $person->{children}[0]{age}    ; # Print Mike's age, omitting
                                              # arrows between subscripts

9. To pretty-print `$person` above:

        use Data::Dumper;
        Data::Dumper->Dumper($person);
        # Or,
        require dumpVar.pl;
        main::dumpValue($person);

B.1 References |  | B.3 Closures