Basic HTML version of Foils prepared Sept 20 97

Foil 53 Functions and Subroutines II

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


1 A comma-separated list of arguments may be used in the calling sequence
2 One can write for subroutines or functions (replace subname by any Perl function)
  • subname LIST; or subname(LIST); # Parentheses are optional
3 This list can be accessed in function using array @_ with elements $_[0],$_[1] etc.
  • $sum = add($a1, $a2, $a3); # a similar routine with arguments (can be variable in number)
  • 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 Sun Sep 21 1997