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


1 The construct local defines variables which are local(private) to a particular function
2 For example the routine on following foil invoked by
3 @new = &bigger_than(100,@list);
4 Returns in @new all entries in @list which are bigger than 100.
5 local() is an executable statement -- not a declaration!
6 The first two statements in bigger_than can be replaced by:
7 local($test,@values) = @_; # local() returns an assignable list
8 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
9 Note can use my/local in any block (not just a function) enclosed in { ... } to define temporary variables of limited scope

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