www.perl.com
Perl Programming
Hierarchical Data
  • References allow you to build hierarchical data structures
    • Arrays and hashes can only contain scalars
    • But a reference is a scalar, even if it refers to an array or a hash
    • Don't even need the arrow operator for these structures

        my $fruits  = ["apple", "bananas", "cherries"];
        my $veggies = ["spinach", "turnips"];
        my $grains  = ["rice", "corn"];
        my @shopping_list = ($fruits, $veggies, $grains);

        print "I should remember to get $shopping_list[2]->[1].\n";
        print "I should remember to get $shopping_list[0][2].\n";
      

        I should remember to get corn.
        I should remember to get cherries.
      
Previous http://stuff.mit.edu/iap/perl/