Basic HTML version of Foils prepared March 30 97

Foil 50 Functions or Subroutines - II (Chapter 8 of the Llama Book)

From PERL4 Tutorial for CPS616 Computational Science for Information Age Course CPS616 -- February 1995. by Geoffrey C. Fox


1 Arguments can be used and a comma separated list can be used as calling sequence
2 One can write for subroutines or functions either (replace subname by any Perl function)
  • subname LIST or subname(LIST); # Parantheses are optional
3 This list can accessed in function using array(list) @_ with elements $_[0],$_[1] etc.
  • $sum = &add($a1,$a2,$a3); # a similar routine with arguments (can be variable in number as a list)
  • sub add {
    • $_[0]+$_[1]+$_[2]; # sum three arguments
    • }

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 Sat Sep 6 1997