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

Arrays

The lists on the previous page weren't very useful - we need some way of saving entire lists for later use and modification.

An array is a named list. As with lists, its space is dynamically allocated and removed, it is 0-indexed, and shares all the operators, and some new accessors

@ (at sign)
Refers to the entire array or slice of an array (when used in conjuction with [ ]).
$ (dollar sign)
Refers to one element of the array, used in conjunction with [ ]
    
	@stringInstruments = ("violin","viola","cello","bass"); 
	@brass = ("trumpet","horn","trombone","euphonium","tuba"); 
	$biggestInstrument = $stringInstruments[3]; 
        print("orchestral brass: ", 
              join(" ",@brass[0,1,2,4] ), 
              "\n"); 
Some Array functions
in addtion to list functions
push(@ARRAY,LIST) add LIST to the end of @ARRAY
pop(@ARRAY) remove and return the last element of @ARRAY
unshift(@ARRAY,LIST) add LIST to the front of @ARRAY
shift(@ARRAY) remove and return the first element of @ARRAY
scalar(@ARRAY) return the number of elements in the array

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/arrays.html at 08/02/99