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


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

in Table To:


© 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