Forum Discussion
Andrea_Arquint
Nimbostratus
Jun 17, 2013using variable in a switch statement
Hi,
I would like to test a URI which is defined as a variable ($TEST_VAR):
when HTTP_REQUEST {
set TEST_VAR "item"
switch -glob [string tolower [HTTP::path]] {
"/$TEST_VAR/*" {...
hoolio
Cirrostratus
Jun 23, 2013If you add a \ at the end of the first line of the switch statement it should work. Here are two forms of the syntax which allow for variables in the switch cases:
when RULE_INIT {
set case1 "test1"
set case2 "test2"
Syntax version 1
switch -glob -- "test2string1" $case1 {
log local0. "matched exact \$case1: $case1"
} $case2 {
log local0. "matched exact \$case2: $case2"
} $case2* {
log local0. "matched starts_with \$case2: $case2"
} default {
log local0. "matched default case"
}
Syntax version 2
switch -glob -- "test2string2" \
$case1 {
log local0. "matched exact \$case1: $case1"
} \
$case2 {
log local0. "matched exact \$case2: $case2"
} \
$case2* {
log local0. "matched starts_with \$case2: $case2"
} \
default {
log local0. "matched default case"
}
}
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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