* RE: Associative Arrays don't work
@ 2006-04-24 9:28 Com MN PG P E B Consultant 3
2006-04-25 9:42 ` DervishD
0 siblings, 1 reply; 4+ messages in thread
From: Com MN PG P E B Consultant 3 @ 2006-04-24 9:28 UTC (permalink / raw)
To: DervishD; +Cc: zsh-users Mailinglist
> * Com MN PG P E B Consultant 3
> <mn-pg-p-e-b-consultant-3.com@siemens.com> dixit:
> > $ zz=() # According to zsh doc, should created any
> array, including associative
>
> I can't find where is that said.
Having reread http://zsh.sunsite.dk/Doc/Release/zsh_14.html#SEC72 again,
I now see
that we have two contradicting statements about this. The first one is
exactly
like you said:
>
On the contrary, what I've found
> is this:
>
> "Associative arrays _must_ be declared before assignment..."
The second information, further down this section, says:
"To create an empty array (including associative arrays), use one of:
set -A name
name=()"
When I saw the "use one of", I was happy enough to not read the whole
section verbatim.
Hence, I had chosen the "name=()" form, believing that it would be
sufficient.
I now see that I has mistakingly believed that creation of an
associative array could
be done without declaring it.
> Try this:
>
> $ typeset -A zz
> $ zz[f]=4
> $ zz[g]=5
> $ print "Here goes zz[f] =>$zz[f] and here zz[g] =>$zz[g]"
> Here goes zz[f] =>4 and here zz[g] =>5
>
> Hope this helps ;) (tested under 4.2.6, BTW)
It does, indeed. Thank you very much!
Ronald
--
Ronald Fischer (phone +49-89-63676431)
mailto:mn-pg-p-e-b-consultant-3.com@siemens.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Associative Arrays don't work
2006-04-24 9:28 Associative Arrays don't work Com MN PG P E B Consultant 3
@ 2006-04-25 9:42 ` DervishD
0 siblings, 0 replies; 4+ messages in thread
From: DervishD @ 2006-04-25 9:42 UTC (permalink / raw)
To: Com MN PG P E B Consultant 3; +Cc: zsh-users Mailinglist
Hi Ronald :)
* Com MN PG P E B Consultant 3 <mn-pg-p-e-b-consultant-3.com@siemens.com> dixit:
[Contradictory documentation]
> > I can't find where is that said.
>
> Having reread http://zsh.sunsite.dk/Doc/Release/zsh_14.html#SEC72
> again, I now see that we have two contradicting statements about
> this. The first one is exactly like you said:
> >
> > "Associative arrays _must_ be declared before assignment..."
>
> The second information, further down this section, says:
>
> "To create an empty array (including associative arrays), use one of:
> set -A name
> name=()"
>
> When I saw the "use one of", I was happy enough to not read the whole
> section verbatim.
What I would have understood from the above is that name=() will
work for both kind of arrays, you're right... I missed that part
(probably because I already know that the "set -A name" is needed).
The docs may be more clear at that point.
> > Hope this helps ;) (tested under 4.2.6, BTW)
>
> It does, indeed. Thank you very much!
You're very welcome ;)
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to... RAmen!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Associative Arrays don't work
@ 2006-04-24 8:31 Com MN PG P E B Consultant 3
2006-04-24 8:48 ` DervishD
0 siblings, 1 reply; 4+ messages in thread
From: Com MN PG P E B Consultant 3 @ 2006-04-24 8:31 UTC (permalink / raw)
To: zsh-users Mailinglist
zsh is supposed to have associative arrays, but they don't work for me.
Here an example:
$ zz=() # According to zsh doc, should created any array,
including associative
$ zz[f]=4 # Set element f to 4
$ echo $zz[g] # Request element g (not f). Element g should not be
there, but we get 4
4
$ zz[g]=5 # Set element g to 5
$ echo $zz[f] # Request element f. We should get 4, but we get 5
5
Hence, "f" and "g" are treated equivalent - not what I would expect from
an associative array.
I googled a bit in the zsh mailing list archive and found a posting from
1998 which claimed
that one should use the -H option to create an associative array. Though
this seems to contradict
the documentation for zsh, I tried the example posted there - and the
result was even more
bizarre:
$ typeset -H assoc
$ assoc[bread]=butter
$ assoc[toast]=jam
$ echo $assoc
jamutter
$ echo $assoc[bread]
j
I tried these examples with the two zsh versions I have access to -
4.0.7 and 4.2.4 - and got
the same result on both.
Ronald
--
Ronald Fischer (phone +49-89-63676431)
mailto:mn-pg-p-e-b-consultant-3.com@siemens.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Associative Arrays don't work
2006-04-24 8:31 Com MN PG P E B Consultant 3
@ 2006-04-24 8:48 ` DervishD
0 siblings, 0 replies; 4+ messages in thread
From: DervishD @ 2006-04-24 8:48 UTC (permalink / raw)
To: Com MN PG P E B Consultant 3; +Cc: zsh-users Mailinglist
Hi Ronald :)
* Com MN PG P E B Consultant 3 <mn-pg-p-e-b-consultant-3.com@siemens.com> dixit:
> $ zz=() # According to zsh doc, should created any array, including associative
I can't find where is that said. On the contrary, what I've found
is this:
"Associative arrays _must_ be declared before assignment..."
> $ zz[f]=4 # Set element f to 4
> $ echo $zz[g] # Request element g (not f). Element g should not be there, but we get 4
Of course, "g" is zero, so you get the zeroth element from the
array you just vivified.
> $ zz[g]=5 # Set element g to 5
> $ echo $zz[f] # Request element f. We should get 4, but we get 5
Idem. You assigned to element zero, so you modified it.
Try this:
$ typeset -A zz
$ zz[f]=4
$ zz[g]=5
$ print "Here goes zz[f] =>$zz[f] and here zz[g] =>$zz[g]"
Here goes zz[f] =>4 and here zz[g] =>5
Hope this helps ;) (tested under 4.2.6, BTW)
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to... RAmen!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-04-25 9:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-24 9:28 Associative Arrays don't work Com MN PG P E B Consultant 3
2006-04-25 9:42 ` DervishD
-- strict thread matches above, loose matches on Subject: below --
2006-04-24 8:31 Com MN PG P E B Consultant 3
2006-04-24 8:48 ` DervishD
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).