iRule: List vs Array

A user recently posted a question asking why when he iterated through an array, created with "array set", it did not process the elements in the order they were defined.

is it possible that an array in tcl has not a defined order? Is there an easy to use ordered list or something like this?

UnRuleY responded with the ins-and-outs of lists vs. arrays

In Tcl, a list is really an ordered array. An array is really a hash. So, the order in which an array is iterated across depends on the hash of the entries and would appear completely random. If you always want to iterated in a specific order, then you likely want a list instead.

Here are a few examples of defining lists in TCL:

set mylist {abc def ghi}

or

set mylist [list abc def ghi]

or

lset mylist abc def ghi

UnRuleY talks a bit more about special characters in list values as well.

If you write iRules at all, you should keep a link to the TCL Reference Manual close by. It can come in very handy in situations like this...

Click here for the original post

-Joe

Published Sep 27, 2005
Version 1.0

Was this article helpful?

No CommentsBe the first to comment