Forum Discussion
Frank_J_104756
Nov 04, 2009Historic F5 Account
comparing variable values
I have 4 counter variables that are set. I've incremented them based on the of times certain strings are seen in an array. I now need to compare these 4 different variables so that I can find out which has the lowest value
foreach lbentry [array names ::sessionlbarray] {
switch $lbentry {
$server1ip {set server1lb [expr {$server1lb} + 1]}
$server2ip {set server2lb [expr {$server2lb} + 1]}
$server3ip {set server3lb [expr {$server3lb} + 1]}
$server4ip {set server4lb [expr {$server4lb} + 1]}
}
}
what is the easiest way to compare the variables server1lb, server2lb, server3lb, and server4lb so that I can find the one w/ the lowest value ?
- The_Bhattman
Nimbostratus
On the top of my head you can do the following: - Frank_J_104756Historic F5 AccountThank you CB...I'll give this a shot...it's looks like it'll do exactly what I want...compare the value but give me the variable name I want.
- Frank_J_104756Historic F5 Accountline 49: [undefined procedure: $server1lb] [{$server1lb} {$server2lb} {$server3lb} {$server4lb}]
- The_Bhattman
Nimbostratus
I am not sure about this but another one that popped in my head is the following: - Frank_J_104756Historic F5 AccountWhat I got to pass the syntax check and what makes sense to me is
- hoolio
Cirrostratus
Hey CB, I think max and min were only added to TCL in v8.5 (iRules use 8.4 currently). Also, Frank, do you want to get the lowest value or to know which variable name has the lowest value? I think the examples so far will return the value--not the variable name. - Frank_J_104756Historic F5 AccountAaron, initially I wanted the variable name w/ the lowest value but actually gettng the value will work since i'm usnig the values as the index in the array. Using the value I can retrieve the correct associated variable
- hoolio
Cirrostratus
Also, make sure to use lindex 0 to get the lowest value as TCL lists are 0 indexed.when RULE_INIT { set var0 4 set var1 3 set var2 2 set var3 1 set var4 0 log local0. "Sorted: [lsort -integer [list $var0 $var1 $var2 $var3 $var4]]\ -> lowest: [lindex [lsort -integer [list $var0 $var1 $var2 $var3 $var4]] 0] " }
- Frank_J_104756Historic F5 Accountthx for mentioning the 0 index Aaron, I'd have been scratching my head over that !!
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