From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HTML_MESSAGE,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 23538 invoked from network); 9 Jan 2024 19:22:37 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 9 Jan 2024 19:22:37 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1704828157; b=ZJieEHUdy0viDhaOMKHHZDkDKg9uINTPaTpfVEUkqzjjySjvlv1VDPJ8pQ8xlOE4N8OFyl5sLG Jw2hX51gjF2bRVWRSVMNB2gE9v388tm2BTdQ9Q0EZUoSs/g5sgQ5aSwPfofLgIcysI+41ihlBT QKiDbZPkK5rMXfwIxFK9H6a4CpAPBXFefM0LzNAiSve424/5Xw8MT4Dua/nIP4UiIG+IUuyIok ul7PxYglK2TUhZFrmWtUdqKNl9DxGfIbGG4IrEs095TNsC2Ov61h3wA9uBmasmR45BnS29gUdI 5vXYSXPC1lHOTEHmKAs+iQJIgKwUZ1zJ8sv+cSxxh7e1/Q==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta03.eastlink.ca) smtp.remote-ip=24.224.136.9; dmarc=none header.from=eastlink.ca; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1704828157; bh=F3W90sFUNHhAqPN2XlAn/405BEwJ0s3SwfuRfQ1WjxI=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Subject:From:To:MIME-Version:Date:Message-ID:Content-Type: DKIM-Signature; b=B2YFUkO0eOBM6OL9qHjMcal/WVZVMK13qLzRJivb82ZNtzFY/3W3c6ovEvxON4oMFRIoa5nqMm yEj04h9r/f+LdfupL2KlJ1GDoweljjMBQfbVATVNLga3RVaifBnY21iqbGJb/F+tHkq+cMK1by ktVXTRS4iO7WLqZXSqok+p0cRN71TpJD2vLdjF1M35skpOzM17s7hiA7AGvFEUlI5ckMTr18+s z0mHwMLSN/hA5Rg+H8rXW8vsqd13te2RRmnpmM7qEoXKTzUOi3vMNjwobDTEBR5VKU9ZUGKSbt Ds+LzaZKCLkx5mk/ntWXheNVyi1CUJ6jbV4jNLWVW5NjLw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Subject:From:To:MIME-version:Date: Message-id:Content-type:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=KMXjJxsyGC7W7JNWL6llobIwRYwA+vGzfoLKkER0SbU=; b=iMgqXKqImErWcXosF7+wqbJ5FF FKsRorPRH1FcziPKx+dsmu+0keSYbcgNNgAlvpaa2BUY2Al8u+pXrJrePL+sz83LtP+9qhz/loSbP LBAazMjSgPP5F8e36Dslah4MmWk/uJIjEc8SWiS+kJMOZYDpIgkFT/WBI+Ybx/W4uPafu/04xjtmq to8Wc4nWSITzzJ4pvSrzvcHPeDBfqsCXnuNCw8XqR1PB5mFLUzDeVsPEDPIJyfENlOvN0ttrTT3gS 14gi53QCQzd8+TvJNqwzqB/yyazcrzLKV/GREev0cSlwBdyJg1jmRs0lkaldQzqz22yancwNAMwF8 CTn2OGfw==; Received: by zero.zsh.org with local id 1rNHLK-000IK5-0r; Tue, 09 Jan 2024 19:00:54 +0000 Authentication-Results: zsh.org; iprev=pass (mta03.eastlink.ca) smtp.remote-ip=24.224.136.9; dmarc=none header.from=eastlink.ca; arc=none Received: from mta03.eastlink.ca ([24.224.136.9]:41487) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rNHKL-000HdA-7b; Tue, 09 Jan 2024 18:59:56 +0000 Received: from csp01.eastlink.ca ([71.7.199.166]) by mta03.eastlink.ca ([24.224.136.9]) with ESMTPS id <0S701ETKQCNLC5L0@mta03.eastlink.ca> for zsh-users@zsh.org; Tue, 09 Jan 2024 14:59:51 -0400 (AST) Received: from [192.168.0.11] (host-24-207-19-13.public.eastlink.ca [24.207.19.13]) by csp01.eastlink.ca ([71.7.199.166]) with ESMTPSA id NHKJri582AItUNHKJrBeLS (version=TLSv1_2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256); Tue, 09 Jan 2024 14:59:51 -0400 X-Authority-Analysis: v=2.4 cv=NJYTuW2g c=1 sm=1 tr=0 ts=659d97a7 a=e7T7DzMKK1R988ZCg0wLyw==:117 a=e7T7DzMKK1R988ZCg0wLyw==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=DUPiqGVcDJjoN2dOjEIA:9 a=QEXdDO2ut3YA:10 a=4FgV1DG21aGrNNiTfvIA:9 a=RxChWPDTqnFk5Moa:21 a=_W_S_7VecoQA:10 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdehledguddukecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfgtefuvffnkffpmfdpqfgfvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurheptgfkffggfgfvhffusegrtderredtvdejnecuhfhrohhmpeftrgihucetnhgurhgvfihsuceorhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrqeenucggtffrrghtthgvrhhnpeeffeeivddtkedvgfetkeevudfhtdeltdegtedttdekieffhfeuhfekheegtdevteenucfkphepvdegrddvtdejrdduledrudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdegrddvtdejrdduledrudefpdhhvghloheplgduledvrdduieekrddtrdduudgnpdhmrghilhhfrhhomheprhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepreerpdhrtghpthhtohepiihshhdquhhsvghrshesiihshhdrohhrghdpghgvthdqkghiphfrrghsshifugepthhruhgv X-Vade-Score: -100 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Content-type: multipart/alternative; boundary="------------Pc0fOO2JNZUUzou0NloKBoSZ" Message-id: <41f9b4d6-8f4a-4220-a86a-b7ccf690bd89@eastlink.ca> Date: Tue, 9 Jan 2024 10:59:50 -0800 MIME-version: 1.0 User-Agent: Mozilla Thunderbird Content-language: en-US To: Zsh Users From: Ray Andrews Subject: proxy name for array X-Seq: 29436 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: This is a multi-part message in MIME format. --------------Pc0fOO2JNZUUzou0NloKBoSZ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit typeset -A body=() LIST=( one two three four five ) body[array]=LIST proxy=$body[array] # But name of array could change. echo $proxy # Comical efforts included for a laugh ... but you see what I'm trying to do: # proxy[2]=TWO # $~proxy[2]=TWO # ${(P)proxy[2]}=TWO # ${(P)proxy}[2]=TWO # eval "${(P)proxy}[2]=TWO" # eval "$proxy[2]=TWO" # eval "${(P)proxy[2]}=TWO" # eval ${(P)proxy[2]}=TWO echo 'hoping for: one TWO three four five :-(' echo $LIST # Not changed. ... I'm not sure I've ever attempted anything like the above.  I want 'proxy' to hold an arbitrary array name and serve if place of an actual name.  '(P)' does this kind of work on the sending side of an assignment, but not on the receiving side and I'm not sure you can ever do an  expansion there anyway -- looks bloody awful. But my (usually) false friend 'eval' works does work like this:     eval "${proxy}[2]=TWO" # ... and having finally nailed it, it's intuitive and obvious why this works and the monstrosities above do not :-(     echo $LIST # Done! ...  But Bart always cautions against it, so I'm wondering if there's a more kosher way.  BTW I had previously been copying entire arrays, making changes and then copying them back, but why not just use the proxy name for whatever the actual name of the array might be?  This is 'pointer think' of course. And I know we don't officially have pointers but this is a pretty good approximation. --------------Pc0fOO2JNZUUzou0NloKBoSZ Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


typeset -A body=()
LIST=( one two three four five )
body[array]=LIST
proxy=$body[array] # But name of array could change.
echo $proxy
# Comical efforts included for a laugh ... but you see what I'm trying to do:
# proxy[2]=TWO
# $~proxy[2]=TWO
# ${(P)proxy[2]}=TWO
# ${(P)proxy}[2]=TWO
# eval "${(P)proxy}[2]=TWO"
# eval "$proxy[2]=TWO"
# eval "${(P)proxy[2]}=TWO"
# eval ${(P)proxy[2]}=TWO
echo 'hoping for: one TWO three four five :-('
echo $LIST # Not changed.

... I'm not sure I've ever attempted anything like the above.  I want 'proxy' to hold an arbitrary array name and serve if place of an actual name.  '(P)' does this kind of work on the sending side of an assignment, but not on the receiving side and I'm not sure you can ever do an  expansion there anyway -- looks bloody awful.  But my (usually) false friend 'eval' works does work like this:

    eval "${proxy}[2]=TWO" # ... and having finally nailed it, it's intuitive and obvious why this works and the monstrosities above do not :-(

    echo $LIST # Done!

...  But Bart always cautions against it, so I'm wondering if there's a more kosher way.  BTW I had previously been copying entire arrays, making changes and then copying them back, but why not just use the proxy name for whatever the actual name of the array might be?  This is 'pointer think' of course. And I know we don't officially have pointers but this is a pretty good approximation.



--------------Pc0fOO2JNZUUzou0NloKBoSZ--