Todd,
Thanks for the explanation.

Jeff

On Thu, 30 May 2024 at 21:56, Todd C. Miller <todd.mil...@sudo.ws> wrote:
>
> On Thu, 30 May 2024 21:42:08 +0100, Jeff Penn wrote:
>
> > I spotted the following issue, which is also present in FreeBSD.
> >
> > $ awk -V
> > awk version 20240122
> > $ awk 'BEGIN {split("A B C", ABC, " ");for (x in ABC) {print x}}'
> > 2
> > 3
> > 1
>
> This is not a bug.  An awk associative array is effectively a hash
> table so when you iterate over it like this you are not guaranteed
> to get things in any particular order.  In fact, our awk, mawk and
> gawk all produce different output when given that snippet.
>
> If you want consistent ordering you need to use the other form of
> for() where you iterate over the array with keys in ascending (or
> descending) order.
>
>  - todd

Reply via email to