'array unset' inconsistency ?
Closed / Invalid1022151fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 20 years ago
Descriptionplain2004-09-03 23:20:22
IMHO the behaviour of the command
'array unset ?pattern?'
is inconsistent, and the problem is exacerbated by an
ambiguous description in its manpage.
Take an array variable, add some elements, then execute
(1) unset a
(2) array unset a
(3)array unset a *
[This has to be done independently, not one after the
other]
Tracing and checking the results of the commands shows
that the scenarios (1) and (2) are equivalent. Whereas
the regular pattern for this type of command is to make
(2) and (3) equivalent.
However when reading the documentation for 'array unset'
it seems to imply the (2)/(3) equivalence:
Unsets all of the elements in the array that match
pattern(using the matching rules of string match).
[...] If pattern is omitted and arrayName is an
array
variable, then the command unsets the entire array.
Because of the first sentence it can be assumed while
reading the last sentence that 'unsetting the entire array'
means the removal of all elements in the array, and not
the removal of the variable.
Only then reading them disconnected it becomes clear
that the last sentence means that the variable is unset,
not its elements.
Either documentation or behaviour should be fixed.
Preferably both.
dkfplain2004-09-06 18:03:07
Logged In: YES user_id=79902 IMO the behaviour is inconsistent with the way the rest of the core operates (in terms of filtering) and so is *wrong*. I think we should fix the code and make sure that the documentation says what it should as well. Note that this may be a POTENTIAL INCOMPATABILITY, but it is at least following the Principle of Least Surprise...
hobbsplain2004-09-08 05:44:44
Logged In: YES user_id=72656 fix the docs, as the behavior is correct as originally designed.
hobbsplain2004-09-08 06:01:46
Logged In: YES user_id=72656 To clarify further, (3) allows the array to remain, while (2) will make it go away - but only if it is an array. These are noops for non-array vars, as specified in the docs, which is why these key diffs are important: Unsets all of the elements in the array that match \fIpattern\fR (using the matching rules of \fBstring match\fR). If \fIarrayName\fR isn't the name of an array variable or there are no matching elements in the array, no error will be raised. If \fIpattern\fR is omitted and \fIarrayName\fR is an array variable, then the command unsets the entire array. The command always returns an empty string.
msofer Pending ticket [1022151fff].
[History diff]2006-10-01 02:32:11
sf-robotplain2006-10-15 09:20:08
Logged In: YES user_id=1312539 This Tracker item was closed automatically by the system. It was previously set to a Pending status, and the original submitter did not respond within 14 days (the time period specified by the administrator of this Tracker).
Log in (anonymous is fine) to add a comment.