if { [string length $sort_dest_pool] > 0 } {
set dest_pool [string trimleft $sort_dest_pool "$loc"]
} else {
set dest_pool $orig_pool
}
If $sort_dest_pool is not defined, I get the following error/event:
can't read "sort_dest_pool": no such variable while executing "string length $sort_dest_pool"
According to this error, it is failing while trying to get the string length. This method was suggested as the solution for testing a string to see if it is set. Any ideas?
Yep, you can use [info exists varname] to check if a variable is defined. Or you could set it to a null value by default and then check it later to see if it’s not null:
when HTTP_REQUEST {
if {$some_condition == 1}{
set sort_dest_pool "my_pool"
} else {
set sort_dest_pool ""
}
later...
if {$sort_dest_pool eq ""}{
Take some default action
} else {
pool $sort_dest_pool
}
}