Basic HTML version of Foils prepared March 30 97

Foil 51 Functions or Subroutines - III -- The local and my constructs (Chapter 8 of the Llama Book)

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


The construct local defines variables which are local(private) to a particular function
For example the routine on following foil invoked by
@new = &bigger_than(100,@list);
Returns in @new all entries in @list which are bigger than 100.
local() is an executable statement -- not a declaration!
The first two statements in bigger_than can be replaced by:
local($test,@values) = @_; # local() returns an assignable list
In Perl5, my tends to eplace local as my scope confined to routine but local extends scope to any function called from block in which local statement defined
Note can use my/local in any block (not just a function) enclosed in { ... } to define temporary variables of limited scope



© 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