Forum Discussion
How do you handle a null variable in an irule?
I am using the below logic:
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?
can you try to remove $?
e.g.
% info exists t 0 % set t 1 1 % info exists t 1
7 Replies
- nitass
Employee
- Erik_27939
Nimbostratus
Unfortunately, now I am getting this error:
can't read "sort_dest_pool": no such variable while executing "info exists $sort_dest_pool"Based on that man page you sent on that command, it should have worked. Thoughts?
- nitass_89166
Noctilucent
can you try to remove $?
e.g.
% info exists t 0 % set t 1 1 % info exists t 1- Erik_27939
Nimbostratus
That was the answer. Thanks!!
- nitass
Employee
can you try to remove $?
e.g.
% info exists t 0 % set t 1 1 % info exists t 1- Erik_27939
Nimbostratus
That was the answer. Thanks!!
- hoolio
Cirrostratus
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 } }Aaron
Recent Discussions
Related Content
* 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
