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


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