Basic HTML version of Foils prepared Sept 20 97

Foil 50 The defined undef and exists functions

From Perl5 and Advanced Perl4 Features Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


defined(expr); # where expr is typically a variable such as $list[7]
returns true if expr is defined (i.e. not equal to undef)
undef $scalar; undef @list; undef %hash; # set all elements in passed reference to be undefined -- the argument can also be things like $hash{key};
  • undef on its own represents undefined value for returning from subroutines etc.
undef can be very useful -- for instance you may wish to reuse a hash %parms and execuate undef %parms before re-use.
exists($hash{place}); returns true if place has been defined as a key to %hash-- note this tests existence of associative memory key -- the value $hash{place} may still be undefined!



© 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 Apr 5 1998