bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing the way bash expands associative array subscripts


From: Dennis Williamson
Subject: Re: Changing the way bash expands associative array subscripts
Date: Tue, 6 Apr 2021 15:24:54 -0500

On Tue, Apr 6, 2021, 3:09 PM Greg Wooledge <greg@wooledge.org> wrote:

> On Wed, Apr 07, 2021 at 03:53:43AM +0800, konsolebox wrote:
> > Also if Bash could just store associative array
> > values as a list to preserve store order and stop expanding
> > "${array[@]}" based on the sorted order of the keys, then the slice
> > function can also be applied there.
>
> There is no sorting in the output.  The keys come out in an order that
> only makes sense to the little gerbils inside bash, not to us humans.
> This is common with hash tables, and the same thing happens with python's
> dictionaries, perl's hashes, and tcl's arrays (but not tcl's dictionaries,
> which are closer to what you're envisioning).
>
> unicorn:~$ perl -e 'use Data::Dumper; %hash=qw(a b c d e f g h); print
> Dumper(\%hash);'
> $VAR1 = {
>           'e' => 'f',
>           'g' => 'h',
>           'c' => 'd',
>           'a' => 'b'
>         };
>
> unicorn:~$ tclsh <<'EOF'
> array set hash {a b c d e f g h}; puts [array names hash]
> EOF
> e a g c
>

Python 3.7 has insertion-order dictionaries. So these are dependable
gerbils.

>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]