Discussion:
Are "${!associative_array[@]}" and "${associative_array[@]}" always in the same order?
(too old to reply)
Peng Yu
2018-11-17 05:49:20 UTC
Permalink
Hi,

My test cases shows that "${!associative_array[@]}" and
"${associative_array[@]}" are in the same order. But no test cases can
cover all possible situations. Does anybody know whether they are
always in the same order? Thanks.
--
Regards,
Peng
Greg Wooledge
2018-11-19 13:36:42 UTC
Permalink
Post by Peng Yu
cover all possible situations. Does anybody know whether they are
always in the same order? Thanks.
Why would you care? If you need the indices, you use "${!a[@]}" and
this gives you a list of the indices in some unpredictable order.
You either iterate over this list as-is, or you sort it. You don't
use "${a[@]}" and then wonder whether the two lists match up.
konsolebox
2018-11-21 05:28:38 UTC
Permalink
Post by Peng Yu
Hi,
cover all possible situations. Does anybody know whether they are
always in the same order? Thanks.
Sounds like a feature similar to gawk's that's worth submitting a patch for
for the next version of bash.
Chet Ramey
2018-11-21 14:04:33 UTC
Permalink
Post by konsolebox
Post by Peng Yu
Hi,
cover all possible situations. Does anybody know whether they are
always in the same order? Thanks.
Sounds like a feature similar to gawk's that's worth submitting a patch for
for the next version of bash.
What, exactly, would the feature request be?
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://tiswww.cwru.edu/~chet/
Peng Yu
2018-11-21 14:31:18 UTC
Permalink
To make "${!associative_array[@]}" and "${associative_array[@]}” of the
same order, if they are not guaranteed to be so.
Post by Chet Ramey
Post by konsolebox
Post by Peng Yu
Hi,
cover all possible situations. Does anybody know whether they are
always in the same order? Thanks.
Sounds like a feature similar to gawk's that's worth submitting a patch
for
Post by konsolebox
for the next version of bash.
What, exactly, would the feature request be?
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
--
Regards,
Peng
Chet Ramey
2018-11-21 14:37:14 UTC
Permalink
Post by Peng Yu
same order, if they are not guaranteed to be so.
Inspecting the code to provide a patch would resolve that question
one way or the other. It's left as an exercise for the reader.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://tiswww.cwru.edu/~chet/
Loading...