On Tue, Apr 6, 2021, 3:09 PM Greg Wooledge <g...@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. >