Deutsch English Français Italiano |
<20250210184000.795@kylheku.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: comp.lang.awk Subject: Re: Sorting with GNU Awk Date: Tue, 11 Feb 2025 02:47:04 -0000 (UTC) Organization: A noiseless patient Spider Lines: 42 Message-ID: <20250210184000.795@kylheku.com> References: <voebnd$1fnqi$1@dont-email.me> Injection-Date: Tue, 11 Feb 2025 03:47:08 +0100 (CET) Injection-Info: dont-email.me; posting-host="e2b9f1c82ae753090fca2d1a767cddc0"; logging-data="1570645"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lCvg4Rttbx8WWJa2DpnUAkcGk3KSmCB0=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:6qX30O4AgtxOK1O4LH64lI9xcQ8= Bytes: 2570 On 2025-02-11, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote: > I have an application were I need sorting. My tests led me to > this variant that works as I expected (with GNU Awk 5.3.0) > > asort (arr, res, "@val_num_desc") > > But I originally intended an _inplace_ sort and I thought that > using these commands would also work > > PROCINFO["sorted_in"] = "@val_num_desc" > asort (arr) > > but the sorting order is (contrary to my specifier) ascending. > So it seems PROCINFO is not considered by the asort() function? > (Or is that just inappropriately used?) No it isn't. All I see in the documentation is: - PROCINFO["sorted_in"] controls the "for" traversal of arrays; i.e. for (var in array) and that's it. - The same values that maybe used with PROCINFO["sorted_in"] maybe explicitly passed as an argument to asort/asorti to bring about the same sort order. > Another question; is there a simple way for a _unique sorting_ > like Unix'es 'sort -u'? - By simple I mean some setting, not a > programmed function like using associative array indexes, etc. I don't think so, but if we consider that the indices of an associative array must be unique, then it may be workable to store the data as indices to "uniquefy" it, and use asorti to sort indices rather than values. asorti inverts the array, sort of. The values of the array are lost. The sorted indices become the values of the target array, whose indices are the natural numbers (integers from 1). -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca