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, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 17434 invoked from network); 11 Dec 2022 17:40:42 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 11 Dec 2022 17:40:42 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1670780443; b=PzOKrw5gzr2FyF8fyd3lgUim9ncWJp+shlPMampA9/6eOrgtlDJ19bT1N4zYkOC3BA+i9loDom pKG4mVg71X2r6622QHZ7YkSHRT3j1uCLtQVZwJRPMO3FTXx8KS77wzlytLge1DBqJ/rTc29NOE X5S0ruVYxvqA0zQM40BtFiKlyGXyc4sS2GqG0NhJB47d1bZN61Y/4/cdFiglrLqZ5il9dGxK3W Y1egcJ9ofjqStKLIQYkmQWP0KWXfUJXgWclHzZFsIeQbUVH0l9QcUf3tOSVrrg3Pe3Wk7JObZu 9JV4jntQKqZF87ousIPsADShTMiQZMyncf1kJT/86Yo2cA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta01.eastlink.ca) smtp.remote-ip=24.224.136.30; 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=1670780443; bh=RDTwmYSUtxEAqZ2AQFxEdvrXTSM3tfiPvJCaW03lchg=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Subject:From:To: MIME-Version:Date:Message-ID:DKIM-Signature; b=SvBWKwcd0zgCWlRthnSOHzSFy31Q1Yo4fwBd74EzJBdd6jPI4MRoTEMP3e38QFz3j+63LwryeP v2qvJGHLK5I8T0fVfiOpODw/4NZMyBbMktdyQYAYfgPbA9zMbp8X25xgbVBWpRCJtJJ4u5BNJ4 YNN+9iLxOH4lbE5Vv4xD+yiHFJ9vYNBnrINY9eTvOdOv4JhKwTJewDDm8dGRyu7J3cD3S1NTn2 Hd6BnDigRqGx8bMJmlnPwE2uQhIThq1az9qNcRgOnre/dZGhuGDrbL1RCfYGqyrrmICcwoev30 Z+qAkDw8c6jm2bcK2dhKH6ncxDfXIX39Xf8h8kO0mFwNfw==; 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:Content-transfer-encoding: Content-type:Subject:From:To:MIME-version:Date:Message-id:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=G5w68njVs4qo9W84mlo+IJb0BjBq+pBB3Ln9mYCRJ0c=; b=TNdl7C+75+7kbG1HqWG/JP8F+8 MjbcWI87An67oLYXIIEqXXEdDZRprxZtGnLohLEU0AtCRX/GMQzydkE7UTM3QmktO9i/pweIrlJN2 6dJUT7nkz6z2ZamNpTC5i8GkLAm77sx2lpjh5dlrdJftm+dF/XHBPNGHkQWRzRqzVehUK9IzqyjaJ o2xAsc4jBnsJ1pF7GYCwrXnmO/QU4epodESG5zLyvyofv+Qj7UZVJj9zlpNRQBJZqEggboyGCp7Z2 SCjCGidAyfJF9qShMFEZDraxfgvk4wB//EDiztfX/IiAT7t5qyqCrUeXboi5Zui1Bg1fWQBCwfLHv /Hnlv2wg==; Received: by zero.zsh.org with local id 1p4QJd-000OZd-S8; Sun, 11 Dec 2022 17:40:41 +0000 Authentication-Results: zsh.org; iprev=pass (mta01.eastlink.ca) smtp.remote-ip=24.224.136.30; dmarc=none header.from=eastlink.ca; arc=none Received: from mta01.eastlink.ca ([24.224.136.30]:59912) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1p4QIt-000Nrt-DK; Sun, 11 Dec 2022 17:39:56 +0000 Received: from csp01.eastlink.ca ([71.7.199.166]) by mta01.eastlink.ca (Oracle Communications Messaging Server 8.0.2.2.20180531 64bit (built May 31 2018)) with ESMTPS id <0RMQ00O6YM9N5M30@mta01.eastlink.ca> for zsh-users@zsh.org; Sun, 11 Dec 2022 13:39:53 -0400 (AST) Received: from [192.168.0.4] ([24.207.18.108]) by Eastlink with ESMTPSA id 4QIqpQIGhEN8v4QIrpgwB3; Sun, 11 Dec 2022 13:39:53 -0400 X-Authority-Analysis: v=2.4 cv=IPDESCjG c=1 sm=1 tr=0 ts=639615e9 a=xN66ZtSbq5jdJYpBp7G/jQ==:117 a=xN66ZtSbq5jdJYpBp7G/jQ==:17 a=IkcTkHD0fZMA:10 a=leEe-xIOeuVszrH3czgA:9 a=QEXdDO2ut3YA:10 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeigddutdegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefkffggfgfvhffutgfgsehtkeertddtfeejnecuhfhrohhmpeftrgihucetnhgurhgvfihsuceorhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrqeenucggtffrrghtthgvrhhnpeevhedugeetieevveeiueethfffleehkeeugeehtdehgfetjeevhffgkefhieegffenucfkphepvdegrddvtdejrddukedruddtkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvgedrvddtjedrudekrddutdekpdhhvghloheplgduledvrdduieekrddtrdegngdpmhgrihhlfhhrohhmpehrrgihrghnughrvgifshesvggrshhtlhhinhhkrdgtrgdpnhgspghrtghpthhtohepvddprhgtphhtthhopeerredprhgtphhtthhopeiishhhqdhushgvrhhsseiishhhrdhorhhgpdhgvghtqdgkihhprfgrshhsfigupehtrhhuvg X-Vade-Score: -100 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Message-id: Date: Sun, 11 Dec 2022 09:39:52 -0800 MIME-version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Content-language: en-US To: Zsh Users From: Ray Andrews Subject: associative array questions Content-type: text/plain; charset=UTF-8; format=flowed Content-transfer-encoding: 8bit X-Seq: 28516 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: Experimenting with associative arrays: typeset -Ag aa IN test1 () {     aa[first]=1     aa[second]=two     aa[third]='three blind mice' } test2 () {     set -A IN ${(Pkv)${1}}     IN[second]='tea for two'     set -A "$1" ${(kv)IN} } test3 () {     aarray="$1"     print "aa[second] is: ${${(P)aarray}[second]}" # BAD: #    ${(P)aarray}[second]='tea for two' # GOOD:     eval "${aarray}[second]='tea for two'"     print "\naa changed:\n"     printf "%-10s %s\n" ${(kv)aa} } ... test2 works fine and it's how my existing code does it. test2 and test3 might have to chew on one of several possible arrays so the use of '$1' is necessary.  However, C-brained as I am, I'm wanting to link to the input array directly via a pointer sort of operation so in test3 I'm trying to grab the name of the target array and modify it (the array) directly. The 'print' works fine.  So I think to myself: strip off the outer '${}' and now we have the name of the element, not it's expansion, so an assignment should be possible, but it doesn't work.  '${(P)aarray'} should expand to 'aa' remembering that it's a variable -- so I think. However doing it via 'eval' works.   In practice test2 has the more streamlined code but I'm still curious that the BAD attempt at an assignment doesn't work.  I know I'm thinking too visually. BTW, it's also unexpected that the array prints upside down: $ . test1; test1; test3 aa aa[second] is: two aa changed: third        three blind mice second    tea for two first        1 ... are associative arrays appended at the top?  I know that with associative arrays the element order isn't the primary thing but still.