www.perl.com
Perl Programming
Arrays
  • May be sliced
    • A slice (or sub-array) is itself an array
    • Take an array slice with @array[@indices]
    • $array[0] is a scalar, that is, a single value
    • @array[0] is an array, containing a single scalar
    • Scalars always begin with $
    • Arrays always begin with @

        my @fruits = qw(apples bananas cherries oranges);

        my @yummy = @fruits[1,3];
        print "My favorite fruits are: @yummy\n";

        my @berries = @fruits[2];
        push @berries, "cranberries";
        print "These fruits are berries: @berries\n";
      

        Output:
        My favorite fruits are: bananas oranges
        These fruits are berries: cherries cranberries
      
Previous http://stuff.mit.edu/iap/perl/