Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Qmail-Scanner-Diagnostics: from out2-smtp.messagingengine.com by f.primenet.com.au (envelope-from <vq@larryv.me>, uid 7791) with qmail-scanner-2.11 
 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1.  
 Clear:RC:0(66.111.4.26):SA:0(0.0/5.0):. 
 Processed in 0.16093 secs); 21 Aug 2016 21:18:23 -0000
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_PASS,T_DKIM_INVALID
	autolearn=unavailable autolearn_force=no version=3.4.1
X-Envelope-From: vq@larryv.me
X-Qmail-Scanner-Mime-Attachments: |
X-Qmail-Scanner-Zip-Files: |
Received-SPF: pass (ns1.primenet.com.au: SPF record at spf.messagingengine.com designates 66.111.4.26 as permitted sender)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=larryv.me; h=cc
	:content-transfer-encoding:content-type:date:from:in-reply-to
	:message-id:mime-version:references:subject:to:x-sasl-enc
	:x-sasl-enc; s=mesmtp; bh=7bZLlPi8UJ37oP80rFWNSVeBDkg=; b=d0MUvK
	7r5FM/0iWXUDMS+aRZVYr8E1Zr9YrsgA8bqI8W0apU0NbQ7FotB2moRXMMF9Z/lV
	Al52FG8k2a7mow86e/yMHeYRyd7z+PwCEgtsAMbROoeF1uXOCN4ePs2rL2AZSl+m
	qwTQqYJQFM65aBNiCKiZR9VQRE1kAzd5g5nCo=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=
	messagingengine.com; h=cc:content-transfer-encoding:content-type
	:date:from:in-reply-to:message-id:mime-version:references
	:subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=7bZLlPi8UJ37oP8
	0rFWNSVeBDkg=; b=BGrlPkSMdX995UuwwDwN25lsIZ5WbXdraY4NKbbnNNb7Q35
	OCHbtkJGLX8iYONbKYuMyFoG+lKZCEnbWsvZy5XxWKSfzAMatjJSqx9dySDBx3Mm
	tcU7yTjD3qmaqRyiglvX2yBdb4v2Vs5ikOdOu0M0ceYFVAuIwUbxdrET+7Zg=
X-Sasl-enc: KWpIgH4Crs6C5f3cJCOElFKGeZCys54DEqjNhGRL4HJ6 1471814292
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\))
Subject: Re: Help with associative arrays
From: =?utf-8?Q?Lawrence_Vel=C3=A1zquez?= <vq@larryv.me>
In-Reply-To: <CACeGjnUfMEo5KtdMn=iiAVsfAJgjeVyk7vh+WFZgcyKeahBbnQ@mail.gmail.com>
Date: Sun, 21 Aug 2016 17:18:11 -0400
Cc: zsh-workers@zsh.org
Content-Transfer-Encoding: quoted-printable
Message-Id: <2D3937A2-41B0-4B31-90D9-3C91D0DFFB92@larryv.me>
References: <CACeGjnUfMEo5KtdMn=iiAVsfAJgjeVyk7vh+WFZgcyKeahBbnQ@mail.gmail.com>
To: acs@alumni.princeton.edu,
 ethersoft@gmail.com
X-Mailer: Apple Mail (2.3124)
X-Seq: zsh-workers 39085

> On Aug 21, 2016, at 4:50 PM, Vin Shelton <ethersoft@gmail.com> wrote:
>=20
> I can't seem to figure this out.  I'm trying to use an associative
> array and the results are not what I expect:
>=20
> #!/usr/bin/env zsh
>=20
> emulate -LR zsh
>=20
> typeset -A repos
> repos["conky"]=3D"https://github.com/brndnmtthws/conky.git"
>=20
> nickname=3D"conky"
> echo "nickname =3D " \"$nickname\" "repos =3D " =
\"${repos[$nickname]}\"
> echo "nickname =3D " \"$nickname\" "repos =3D " \"${repos["conky"]}\"
>=20
> yileds:
>=20
> nickname =3D  "conky" repos =3D  ""
> nickname =3D  "conky" repos =3D  =
"https://github.com/brndnmtthws/conky.git"
>=20
> given that nickname is "conky" I expected the values to be the same.

=46rom zshparam(1):

        The basic rule to remember when writing a subscript expression
        is that all text between the opening `[' and the closing `]' is
        interpreted as if it were in double quotes (see zshmisc(1)).

        [...]

        The second difference is that a double-quote (`"') may appear as
        part of a subscript expression without being preceded by
        a backslash....

The double quotes you're using are not acting as quoting syntax; they
are being treated literally and are becoming part of the key itself.

	% typeset -A repos1; repos1["conky"]=3Dfoo; typeset repos1
	repos1=3D( '"conky"' foo )
	% typeset -A repos2; repos2[conky]=3Dfoo; typeset repos2
	repos2=3D( conky foo )

But the quotes are behaving as you expect when you do the assignment to
"nickname".

	% nickname=3D"conky"; typeset nickname
	nickname=3Dconky

So $repos[$nickname] is evaluated as $repos[conky], not $repos["conky"],
while your array contains a '"conky"' key, not a 'conky' key. In the
end, you're not looking up the key you want.

tl;dr: Don't use double quotes in array subscripts, unless your array
contains keys with literal double quotes.

vq

