www.perl.com
Perl Programming
Arrays
  • Dynamically assume whatever values or size needed
    • Can dynamically lengthen or shorten arrays
    • May be defined, but empty
    • No predefined size or "out of bounds" error
    • unshift and shift add to and remove from the front
    • push and pop add to and remove from the end

        my @fruits;                            # Undefined
        @fruits = qw(apples bananas cherries); # Assigned
        @fruits = (@fruits, "dates");          # Lengthen
        @fruits = ();                          # Empty

        unshift @fruits, "acorn";              # Add an item to the front
        my $nut = shift @fruits;               # Remove from the front
        print "Well, a squirrel would think an $nut was a fruit.\n";

        push @fruits, "mango";                 # Add an item to the end
        my $food = pop @fruits;                # Remove from the end
        print "My, that was a yummy $food!\n";
      

        Well, a squirrel would think an acorn was a fruit.
        My, that was a yummy mango!
      
http://stuff.mit.edu/iap/perl/