Forum Discussion
Thomas_Laubrock
Sep 05, 2005Nimbostratus
foreach iterates an array in reverse order
Hi *,
I just fund a false friend.
A foreachstatement like:
array set ersetzer {
"https://portal.domain:80" "https://portal.domain.net"
"http://portal" "https://portal"
}
foreach {myfind myreplace} [array get ersetzer] {
set offset 0
set diff [expr [string length $myreplace] - [string length $myfind]]
Get indices of all instances of find string in the payload
set indices [regexp -all -inline -indices $myfind [HTTP::payload]]
log "Search for: $myfind, replace with $myreplace, found at indices"
[here same code that replaces the strings in the http payload]
}
runs trough the array in reverse order, so this code will first search for "http://portal" and then for "https://portal.domain.net:80"
Because I need the replacements in the right order it is very important, that you know the untypical behaviour for the foreach statement.
Hopefully the netx release will behave in the same way, otherwies ... goob luck and happy iRule debugging :-)
Bye
Thomas
- Thomas_LaubrockNimbostratusHi,
- unRuleY_95363Historic F5 AccountIn 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.
- Thomas_LaubrockNimbostratusHi,
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects