www.perl.com
Perl Programming
Arrays
  • May be assigned in several ways
    • Items bounded by parentheses and separated by commas
    • Numeric value ranges denoted by .. operator
    • Quoted word lists using qw operator
    • Sublists are "flattened" into a single array

        @prime_numbers = (2, 3, 5, 7, 11, 13);          # Comma-separated
        @composite_numbers = (4, 6, 8..10, 12, 14..16); # Numeric ranges

        @fruits = ("apples", "bananas", "cherries");
        @fruits = qw(apples bananas cherries);          # Same as above

        @veggies = qw(radishes spinach);
        @grocery_list = (@fruits, @veggies, "milk");
        print "@grocery_list\n";
      

        Output:
        apples bananas cherries radishes spinach milk
      
Previous http://www.mit.edu/iap/perl/