Basic HTML version of Foils prepared Sept 20 97

Foil 52 Functions and Subroutines I

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


Functions are defined by the sub construct
  • sub subname {
    • statements;
    • expression defining returned result;
  • }
They are invoked as follows:
  • $sum = add(); # a simple routine with no args
  • sub add {
    • $a1+$a2+$a3; # Sum three global vars
  • }
You can also use the older syntax:
  • $sum = &add;



© 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