From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 857E424715 for ; Fri, 19 Jan 2024 18:16:00 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1705684560; b=swREXqo1KN/YZJtQDrq6jK3z6LtCQjyuTGKgLdsPGdWQ6IIvQbsqP6yn3yre+ZSaFBJWFT3KXY in/PdjHlB0+Lm1P8A257a0zyXY9Mq/Hus0Wf+N+Egoll2axmyGaEd5ewg6FUQRQpVErNlOSxRd aJc1DKsFNY2QhSicjb5Hyne3zoNQSVF07/res+1bbolrMpQxpnXsqDf+zlE9NQnUYibRNKAMc3 53ZDVfEAH/pFld8F4Tdq0WnLqiZkzCll++65JaieJTqr3vm25LHKsKmwjmJP5euQ3FBOB+RNNr 6kK1JF2E0zeuCEXnmfGHmYFsR2wQKJESVFc0Uo46vT5XKw==; 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=1705684560; bh=h9spEQ6xX+X+ZWQYo9XaC6o5RXBe+evNs6/E1FvjyFU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:From:References:To:Subject:MIME-Version:Date: Message-ID:Content-Type:DKIM-Signature; b=HvwvbLX+vJ7PSiQfTe0RGJWt64bkyEyCUQAPMI1ZVelQIM3P9XCz6q6L0nAI3LB0Wn2ae2u0MI FK23FHV5JShhIT1JkFFkW9tZj0bNw5wY3eK5E7+ModO9pM9yiLurYs+cikhPONxECshP+d+blS b4ecREMqOyQQdn939/awBTUWlSkXfAMYM7cXhDlxAERTADBWDiNOlAGCzH8hjRxQjj4rLZ2Uzb VEbRVgTmVnxcIg7TviWg3t0J7ZBFGeoJ5CJb5AoUKlYTB/ly1XpUY4CEbCurhNbrrxuS0YMTWs sg8GwP2ko9cyar4fe9URNKMy0B629zMNpBjjJw3ALhpPZQ==; 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:In-reply-to:From:References:To: Subject: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; bh=ugxMCYtO/V9gjKn+n+uWsze6pLDjltR0V0oAyMWjqpA=; b=mj5CTG4D1gXVLFW1KWw357NQfD HHmnT7uVVWF068g9xE9jhXcSfjDs2EBGErYo35XesCZmW4Da1QVFshd7SmBETY7WMwA5h/7leYxPQ EIQ39puExVJMk6OJKdziBsPKuJIHkDqrz3mQqkt+kWNqBWNqJNkOfVuZrAn4J3IlmwHRpFvieG9Y2 VAHS61D1kE67ychaej2CGlHSUCXX00nqtEKO7PmcBPjYP5WkhEuwDjkwwdIr4TRp6r/vej3tWL8nY BUwRFdKOUA75l38csiTuUuAMKpgBJILJAt9jg0fvt3hvw9kh4l5u2TLu2Y4GmCPH+QTfSc2iNrazK +37hkYvg==; Received: by zero.zsh.org with local id 1rQsTG-0009pv-FH; Fri, 19 Jan 2024 17:15:58 +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]:36733) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rQsSf-0009AN-Jq; Fri, 19 Jan 2024 17:15:22 +0000 Received: from csp02.eastlink.ca ([71.7.199.167]) by mta01.eastlink.ca ([24.224.136.30]) with ESMTPS id <0S7I1C4A7QIA1XQ0@mta01.eastlink.ca> for zsh-users@zsh.org; Fri, 19 Jan 2024 13:15:20 -0400 (AST) Received: from [192.168.0.11] (host-24-207-19-13.public.eastlink.ca [24.207.19.13]) by csp02.eastlink.ca ([71.7.199.167]) with ESMTPSA id QsSdruS8utqGEQsSerIRyT (version=TLSv1_2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256); Fri, 19 Jan 2024 13:15:20 -0400 X-Authority-Analysis: v=2.4 cv=Zvoraf3G c=1 sm=1 tr=0 ts=65aaae28 a=e7T7DzMKK1R988ZCg0wLyw==:117 a=e7T7DzMKK1R988ZCg0wLyw==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=oy0_t0qVaJLwaYHw5HkA:9 a=QEXdDO2ut3YA:10 a=pGLkceISAAAA:8 a=5TqQAACj7YmmQRiJfZMA:9 a=M-qocOT8wDB284s_:21 a=_W_S_7VecoQA:10 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdektddgleejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtderredtvdejnecuhfhrohhmpeftrgihucetnhgurhgvfihsuceorhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrqeenucggtffrrghtthgvrhhnpefhteethfevgeeuvdelgefgvdevudefueduffdvgfelvddvgfdtieegueeuleeifeenucfkphepvdegrddvtdejrdduledrudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdegrddvtdejrdduledrudefpdhhvghloheplgduledvrdduieekrddtrdduudgnpdhmrghilhhfrhhomheprhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepreerpdhrtghpthhtohepiihshhdquhhsvghrshesiihshhdrohhrghdpghgvthdqkghiphfrrghsshifugepthhruhgv X-Vade-Score: 0 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Content-type: multipart/alternative; boundary="------------Zko77yWyFWg4xjru0K4100PZ" Message-id: <6b957d12-4306-4988-83fd-d7b67e42bbea@eastlink.ca> Date: Fri, 19 Jan 2024 09:15:19 -0800 MIME-version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Empty element elision and associative arrays (was Re: Slurping a file) Content-language: en-US To: zsh-users@zsh.org References: <7b20b425-59b2-466d-a9aa-a2768d1d4633@app.fastmail.com> <4b475319-ef78-4d46-a62c-27c3b0af3ea4@eastlink.ca> <49702cd2-814c-4461-9819-cc2b85bd3ea2@eastlink.ca> <50941e8e-86e2-4e89-8644-c863f846e805@eastlink.ca> <20240119102755.5ma5psbccsuo5ohj@chazelas.org> From: Ray Andrews In-reply-to: X-Seq: 29527 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. --------------Zko77yWyFWg4xjru0K4100PZ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2024-01-19 08:01, Mikael Magnusson wrote: > Keys are unique but values aren't, so it's sort of a nonsensical > request; that said, you can do it ;). I dunno, you might have some sort of efficiency test and store the results in an array keyed to the names of the various tests and you want to see them in the order of best to worst. I think that for the time being this works for me: typeset -A array=( [1test_one]=123 [2test_two]=345 [3test_three]=111 [4test_four]=5 ) echo "\nraw" printf "\n%-20s %s" ${(kv)array} echo "\n\nsorted on key" printf "\n%-20s %s" ${(kv)array} | sort echo "\nsorted on value" printf "\n%-20s %s" ${(kv)array} | sort -k2 echo "\nsorted on value numerically" printf "\n%-20s %s" ${(kv)array} | sort -k2g output: 5 /aWorking/Zsh/Source/Wk 0 % . test2 raw # No recognizable order 1test_one            123 2test_two            345 4test_four           5 3test_three          111 sorted on key # If the array itself won't do it, then make 'sort' do it: 1test_one            123 2test_two            345 3test_three          111 4test_four           5 sorted on value # dictionary sort 3test_three          111 1test_one            123 2test_two            345 4test_four           5 sorted on value numerically # numeric sort 4test_four           5    # This isn't going anywhere. 3test_three          111 1test_one            123 2test_two            345  # Here's the winner, congratulations test_two team. ... so however much I think there should be a defined order to the way the arrays print, it seems easy enough to use other tools to do it. --------------Zko77yWyFWg4xjru0K4100PZ Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 2024-01-19 08:01, Mikael Magnusson wrote:
Keys are unique but values aren't, so it's sort of a nonsensical
request; that said, you can do it ;).

I dunno, you might have some sort of efficiency test and store the results in an array keyed to the names of the various tests and you want to see them in the order of best to worst.

I think that for the time being this works for me:


typeset -A array=( [1test_one]=123 [2test_two]=345 [3test_three]=111 [4test_four]=5 )

echo "\nraw"
printf "\n%-20s %s" ${(kv)array}
echo "\n\nsorted on key"
printf "\n%-20s %s" ${(kv)array} | sort
echo "\nsorted on value"
printf "\n%-20s %s" ${(kv)array} | sort -k2
echo "\nsorted on value numerically"
printf "\n%-20s %s" ${(kv)array} | sort -k2g

output:


5 /aWorking/Zsh/Source/Wk 0 % . test2

raw # No recognizable order

1test_one            123
2test_two            345
4test_four           5
3test_three          111

sorted on key # If the array itself won't do it, then make 'sort' do it:

1test_one            123
2test_two            345
3test_three          111
4test_four           5

sorted on value # dictionary sort

3test_three          111
1test_one            123
2test_two            345
4test_four           5

sorted on value numerically # numeric sort

4test_four           5    # This isn't going anywhere.
3test_three          111
1test_one            123
2test_two            345  # Here's the winner, congratulations test_two team.

... so however much I think there should be a defined order to the way the arrays print, it seems easy enough to use other tools to do it.


--------------Zko77yWyFWg4xjru0K4100PZ--