smp_86112
May 04, 2010Cirrostratus
v10 - 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?