[slang-users] iterate the elements of an assoc_array in sorted
order
Jörg Sommer
joerg at alea.gnuu.de
Sat Jun 3 19:42:51 EDT 2006
Hallo John,
"John E. Davis" <davis at space.mit.edu> wrote:
> Jörg Sommer <joerg at alea.gnuu.de> wrote:
>>how is it possible to iterate through an Assoc_Array in sorted order.
>>This is ugly:
>>
>>foreach ( assoc_get_keys(templates)[array_sort(assoc_get_keys(templates))] )
>
> You will have to perform a sort as you have done. I would write the
> above as
>
> keys = assoc_get_keys (templates);
> foreach k (keys[array_sort(keys)]) {...}
>
> which I find somewhat more readable.
Indeed. Why foreach do not output the elements of an assoc_array in
sorted order? Isn't it implemented as a tree and do foreach not traverse
the tree in-order?
Bye, Jörg.
--
Der Klügere gibt so lange nach bis er der Dumme ist.
More information about the slang-users-l
mailing list