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

Array index with empty space

281 views
Skip to first unread message

Alexandru

unread,
Jul 18, 2016, 8:11:28 AM7/18/16
to
Hi,

Why is this not working:

array set a [list 1,"Not working" test]

Thanks.
Alexandru

Don Porter

unread,
Jul 18, 2016, 8:56:53 AM7/18/16
to
On 07/18/2016 08:11 AM, Alexandru wrote:
> array set a [list 1,"Not working" test]

The error message tells you, why didn't you report it?

% array set a [list 1,"Not working" test]
list must have an even number of elements

Drawing it out a bit more:

% set l [list 1,"Not working" test]
1,\"Not working\" test
% array set a $l
list must have an even number of elements
% llength $l
3
% lindex $l 0
1,"Not
% lindex $l 1
working"
% lindex $l 2
test

Root of the problem is you need to review "..." quoting syntax and
recognize that it quotes whole words only.

--
| Don Porter Applied and Computational Mathematics Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|

Ralf Fassel

unread,
Jul 18, 2016, 9:02:39 AM7/18/16
to
* Alexandru <alexandr...@meshparts.de>
| Why is this not working:
>
| array set a [list 1,"Not working" test]

Because the quote character only has its special meaning in tcl when at
the start of a word (roughly spoken).

% set a "b c"
b c

% set a b"c
b"c

HTH
R'

Gerhard Reithofer

unread,
Jul 18, 2016, 9:43:48 AM7/18/16
to
On Mon, 18 Jul 2016, Don Porter wrote:

> On 07/18/2016 08:11 AM, Alexandru wrote:
> > array set a [list 1,"Not working" test]
>
> The error message tells you, why didn't you report it?
>
> % array set a [list 1,"Not working" test]
> list must have an even number of elements

...

> Root of the problem is you need to review "..." quoting syntax and
> recognize that it quotes whole words only.

% array set a [list {1,"Not working"} test]
% parray a
a(1,"Not working") = test

Bye,
Gerhard

--
Gerhard Reithofer - Techn. EDV Reithofer - http://www.tech-edv.co.at

Alexandru

unread,
Jul 18, 2016, 10:03:11 AM7/18/16
to
Thanks Gerhard for the solution.
After so many years, I', still learning about the usage of {}...

Regards
Alex

Alexandru

unread,
Jul 18, 2016, 10:04:21 AM7/18/16
to
Am Montag, 18. Juli 2016 15:02:39 UTC+2 schrieb Ralf Fassel:
> * Alexandru
> | Why is this not working:
> >
> | array set a [list 1,"Not working" test]
>
> Because the quote character only has its special meaning in tcl when at
> the start of a word (roughly spoken).
>
> % set a "b c"
> b c
>
> % set a b"c
> b"c
>
> HTH
> R'

Thanks Ralf, that explains very well.
Cheers
Alexandru

Alexandru

unread,
Jul 18, 2016, 10:05:41 AM7/18/16
to
Indeed, in hindsight it should have posted the error. Sorry...

Gerald W. Lester

unread,
Jul 18, 2016, 12:34:27 PM7/18/16
to
On 7/18/16 8:42 AM, Gerhard Reithofer wrote:
> On Mon, 18 Jul 2016, Don Porter wrote:
>
>> On 07/18/2016 08:11 AM, Alexandru wrote:
>>> array set a [list 1,"Not working" test]
>>
>> The error message tells you, why didn't you report it?
>>
>> % array set a [list 1,"Not working" test]
>> list must have an even number of elements
>
> ...
>
>> Root of the problem is you need to review "..." quoting syntax and
>> recognize that it quotes whole words only.
>
> % array set a [list {1,"Not working"} test]
> % parray a
> a(1,"Not working") = test


Actually, I think the following maybe more appropriate:
% array set a [list {1,Not working} test]
% parray a
a(1,Not working) = test



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

Robert Heller

unread,
Jul 18, 2016, 2:57:45 PM7/18/16
to
At Mon, 18 Jul 2016 11:34:24 -0500 "Gerald W. Lester" <Gerald...@KnG-Consulting.net> wrote:

>
> On 7/18/16 8:42 AM, Gerhard Reithofer wrote:
> > On Mon, 18 Jul 2016, Don Porter wrote:
> >
> >> On 07/18/2016 08:11 AM, Alexandru wrote:
> >>> array set a [list 1,"Not working" test]
> >>
> >> The error message tells you, why didn't you report it?
> >>
> >> % array set a [list 1,"Not working" test]
> >> list must have an even number of elements
> >
> > ...
> >
> >> Root of the problem is you need to review "..." quoting syntax and
> >> recognize that it quotes whole words only.
> >
> > % array set a [list {1,"Not working"} test]
> > % parray a
> > a(1,"Not working") = test
>
>
> Actually, I think the following maybe more appropriate:
> % array set a [list {1,Not working} test]
> % parray a
> a(1,Not working) = test

Depends on whether or not the double quotes are litterally part of the key or
now.

>
>
>

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services

0 new messages