Copyright © tutorialspoint.com

PERL delete Function


Syntax

delete LIST


Definition and Usage

Deletes the specified keys and associated values from a hash, or the specified elements from an array. The operation works on individual elements or slices.

Return Value

  • undef if the key does not exist

  • Value associated with the deleted hash key or array index.

Example

The following (inefficiently) deletes all the values of %HASH and @ARRAY:

    foreach $key (keys %HASH) {
	delete $HASH{$key};
    }

    foreach $index (0 .. $#ARRAY) {
	delete $ARRAY[$index];
    }

And so do these:

 delete @HASH{keys %HASH};

 delete @ARRAY[0 .. $#ARRAY];

Copyright © tutorialspoint.com