Perl's undef function

The undefine function (undef) undefines a scalar variable, an array element or an entire array. If you inhale a large table into an array, undef can be used to clear the array and free up system memory. For example:

open(COUNT,"/path/to/count/file.txt") || die "Can't Open Count Data File: $!\n"; 
@count = <COUNT>;
close(COUNT);
you can later do
undef (@count);
to free up memory resources. However
undef
is best for undefining a single element of a hash array. For example, if you load $hasharray{'element10'} you can do
undef $hasharray{'element10'}

to completely remove the element from the array. Just don't do this if you are iterating over the hash.

undef

does have two other uses that are fairly arcane.

Return to Perl Help


[Our portfolio] [A history of Computers and Networks]
[Perl help] [ABAP help] [MySQL help]
[TCP/IP troubleshooting] [HTML help] [Feedback] [Humor]
Advertise on Golden Ink's Georgia Network


In Association with Amazon.com