Lists
homencsa resources partnershipsoutreachsoftware_tech
alliance searchinside ncsa adv_computingsciencedivisions
left up right comment

Lists

Perl's power is assisted by it's builtin data types and the builtins that deal with them. Lists move us up the ladder of complexity from scalars.

A list is an ordered collection of scalars. Space for lists are dynamically allocated and removed from the program's memory. Each element can be addressed by its integer position in the list. Lists are 0-indexed; the first element is called "0". Typical operators include

( ) (parenthesis)
The list constructor.
, (comma)
The comma is used to separate elements of the list.
[ ] (brackets)
Brackets are used to take slices of the list.
 
        $biggestInstrument = ("violin","viola","cello","bass")[3]; 
        print("orchestral brass: ", 
              join(" ",("trumpet","horn","trombone","euphonium","tuba")[0,1,2,4]), 
              "\n"); 
Some list functions
sort(LIST) return a new list, the sorted from LIST
reverse(LIST) return a new list, the reverse of LIST
join(EXPR,LIST) return a string formed by concatenating each element of LIST joined by EXPR
split(PATTERN,EXPR) return a list formed from each substring of EXPR bordered by PATTERN.

left up right comment



NCSA
The National Center for Supercomputing Applications

University of Illinois at Urbana-Champaign

johnsonb@ncsa.uiuc.edu

Last modified: June 19, 1997



Retrieved by Memoweb from http://www.ncsa.uiuc.edu/General/Training/PerlIntro/lists.html at 08/02/99