Forum Discussion
smp_86112
Cirrostratus
May 04, 2010v10 - local vs. global vars
Trying to wrap my mind around how this variable scope works. I have a simple iRule I'm testing with:
when HTTP_REQUEST {
global client_local [TCP::local_port clientside]
if {$::client_local == 443} {
set protocol "https"
} elseif {$::client_local == 80} {
set protocol "http"
}
log local0. "$protocol"
}
My intent was to initialize this "client_local" global var by placing on VIP1, then applying a logging statement on VIP2 to output the value of the "client_local" var to ensure I understand how this works. But I've tried different ways of defining and referencing the variable (such as "global client_local" and "set $::client_local" and also different ways of referencing the variable after it's been defined ("$client_local" and "$::client_local"), but I can't seem to find the right combination. Can you help me understand how to define and reference global varables please?
- hoolio
Cirrostratus
Hi SMP,when CLIENT_ACCEPTED { switch [TCP::local_port clientside] { 443 { set protocol "https" } default { set protocol "http" } } log local0. "$protocol" }
- smp_86112
Cirrostratus
Thanks for laying out the three different ways to define global variables. Let me narrow this down a bit - I can define a global variable, but how then do I reference it? - hoolio
Cirrostratus
I haven't used the TCL 'global' command before. Per the TCL wiki page on the command, I don't think it could be used in current versions of iRules as there is no support for procs in iRules as of now: - smp_86112
Cirrostratus
I think you are getting too hung up on my example. My example was arbitrary - just a simple way designed to help me understand how to and where I can reference global variables, as opposed to local and static ones. - JRahm
Admin
There is a really informative five-minute video on variables in the iules section on the tutorials page.
- smp_86112
Cirrostratus
Ahh, Jason that was a fantastic reference. That video cleared it all up, and I was able to confirm the behavior I was expecting.
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