Basic HTML version of Foils prepared Sept 20 97

Foil 24 Arrays and Lists of Scalars VII --
Operators on Arrays

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


1 push adds elements at end of a list (array). For example,
2 push(@stack, $new); # equivalent to @stack = (@stack, $new);
3 One can also use a list as the second arg in push:
4 push(@stack, 6, "next", @anotherlist);
5 pop, the inverse operator to push, removes and returns the last element in the list
  • Note chop(@stack) removes last character of each entry of @stack
6 unshift is similar to push, except it works on left (lowest indices) of list. For example,
7 unshift(@INC, $dir);
8 modifies the path for included files on-the-fly
9 shift is to pop as unshift is to push
10 reverse(@list) and sort(@list) leave @list unaltered, but returns reversed and sorted lists, respectively

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