beetlebug▾
/

array unset

Removes the elements of an array that match a pattern, or the whole array.

array unset ARRAYNAME ?PATTERN?

Description

With PATTERN, removes each element whose name matches the glob pattern, with the rules of string match, and the array stays, also when it has no element left. With no PATTERN, removes the whole array variable, as unset does.

A name with no variable is no error. A variable with a plain value stays as it is.

Arguments

ArgumentTypeDefaultDescription
ARRAYNAMEvariable namerequiredThe array.
PATTERNglob patternnoneThe names of the elements to remove.

Returns

An empty string.

Examples

% array set u {x1 1 x2 2 y 3}; array unset u x*; array names u
y

% array unset u; info exists u
0

% array unset nope

% set plain 5; array unset plain; set plain
5

Errors

% array unset
wrong # args: should be "array unset arrayName ?pattern?"
-errorcode TCL WRONGARGS

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also