Basic HTML version of Foils prepared Sept 20 97

Foil 21 Arrays and Lists of Scalars IV -- Element Access

From Tutorial on PERL Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


Note that @fred (an array) and $fred (a scalar) are totally different variables
The elements of @fred are indexed starting at 0 (not 1, as in Fortran)
Elements are referenced by $ NOT @
$a = $fred[0]; # is first element in @fred
PERL interpolates arrays as well as scalars:
$fred[0]= "First element of \@fred";
Indices may be arbitrary integer expressions:
@fred = (0..10); $a = 2;
$b = $fred[$a-1]; # sets $b equal to 1



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Sep 21 1997