zsh-users
 help / color / mirror / code / Atom feed
* 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  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

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  8:31 Associative Arrays don't work Com MN PG P E B Consultant 3
2006-04-24  8:48 ` DervishD
2006-04-24  9:28 Com MN PG P E B Consultant 3
2006-04-25  9:42 ` 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).