Basic HTML version of Foils prepared April 16,1996

Foil 50 The defined undef and exists functions

From Perl5 and Advanced Perl4 Features Computational Science for Information Age Course CPS616 Material -- April 16,1996. by Geoffrey C. Fox


1 defined(expr); # where expr is typically a variable such as $list[7]
2 returns true if expr is defined (i.e. not equal to undef)
3 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.
4 undef can be very useful -- for instance you may wish to reuse a hash %parms and execuate undef %parms before re-use.
5 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!

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