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


push adds elements at end of a list (array). For example,
push(@stack, $new); # equivalent to @stack = (@stack, $new);
One can also use a list as the second arg in push:
push(@stack, 6, "next", @anotherlist);
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
unshift is similar to push, except it works on left (lowest indices) of list. For example,
unshift(@INC, $dir);
modifies the path for included files on-the-fly
shift is to pop as unshift is to push
reverse(@list) and sort(@list) leave @list unaltered, but returns reversed and sorted lists, respectively



© 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