[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Changing the way bash expands associative array subscripts
From: |
Greg Wooledge |
Subject: |
Re: Changing the way bash expands associative array subscripts |
Date: |
Tue, 6 Apr 2021 16:09:06 -0400 |
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
- Re: Changing the way bash expands associative array subscripts, (continued)
- Re: Changing the way bash expands associative array subscripts, Chet Ramey, 2021/04/05
- Re: Changing the way bash expands associative array subscripts, Koichi Murase, 2021/04/06
- Re: Changing the way bash expands associative array subscripts, Greg Wooledge, 2021/04/06
- Re: Changing the way bash expands associative array subscripts, Koichi Murase, 2021/04/06
- Re: Changing the way bash expands associative array subscripts, Greg Wooledge, 2021/04/06
- Re: Changing the way bash expands associative array subscripts, Ilkka Virta, 2021/04/06
- Re: Changing the way bash expands associative array subscripts, Greg Wooledge, 2021/04/06
- Re: Changing the way bash expands associative array subscripts, Ilkka Virta, 2021/04/06
- Re: Changing the way bash expands associative array subscripts, konsolebox, 2021/04/06
- Re: Changing the way bash expands associative array subscripts,
Greg Wooledge <=
- Re: Changing the way bash expands associative array subscripts, Dennis Williamson, 2021/04/06
- Re: Changing the way bash expands associative array subscripts, Greg Wooledge, 2021/04/06
- Re: Changing the way bash expands associative array subscripts, konsolebox, 2021/04/06
- Re: Changing the way bash expands associative array subscripts, Koichi Murase, 2021/04/06
- Re: Changing the way bash expands associative array subscripts, Greg Wooledge, 2021/04/06
- Re: Changing the way bash expands associative array subscripts, Chet Ramey, 2021/04/08
- Re: Changing the way bash expands associative array subscripts, Greg Wooledge, 2021/04/08
- Re: Changing the way bash expands associative array subscripts, Koichi Murase, 2021/04/08
- Re: Changing the way bash expands associative array subscripts, Chet Ramey, 2021/04/09
- Re: Changing the way bash expands associative array subscripts, Koichi Murase, 2021/04/09