Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[array unset] gotcha

20 views
Skip to first unread message

John Seal

unread,
Sep 13, 2007, 7:48:18 AM9/13/07
to
A coworker came to me this morning with a problem:

(bin) 1 % set bar {x[y]}
x[y]
(bin) 2 % set foo($bar) test
test
(bin) 3 % parray foo
foo(x[y]) = test
(bin) 4 % array unset foo $bar
(bin) 5 % parray foo
foo(x[y]) = test

His claim was that you couldn't unset array elements whose names
contained square brackets. I pointed him to the array man page, which
says that [array unset] uses the rules of [string match], to which
square brackets are significant. Then I showed him:

(bin) 6 % unset foo($bar)
(bin) 7 % parray foo
(bin) 8 %

A simple problem, but possibly a "gotcha". My first thought was that he
must be doing something to evaluate the [].

Arjen Markus

unread,
Sep 13, 2007, 8:23:03 AM9/13/07
to

Hm, but the pattern would be * as you do not specify any special
one, so that should match anything. Odd

Regards,

Arjen

Arjen Markus

unread,
Sep 13, 2007, 8:41:41 AM9/13/07
to
> Arjen- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Oh, missed a piece of information :-} You do give a pattern.

Yes, glob patterns can contain ranges - like "x[y]" ...

Regards,

Arjen

Gerald W. Lester

unread,
Sep 13, 2007, 8:48:20 AM9/13/07
to

You could also do:
% array unset foo [string map {[ \\[ ] \\]} $bar]

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

0 new messages