Forum Discussion
Scope of variables when using call
- Dec 05, 2022
The proc does not inherit the variables from the caller. It will inherit all static variables and functions eg HTTP::path, but there are two ways to allow these variables in the procedure - either send them as calling variables, or use upvar.
Sending them as variables is more dependable - you don't need to worry about naming or suchlike but you can end up sending a lot of information. Add this to the procedure eg
proc process_URL {var1 var2 var3 {optionalvar "default value"} } { ... }You can also only have a single variable but make it a list.
Upvar depends on naming of variables to import a specific variable into the proc scope. Very useful if you want to modify the original variable, but open to errors if the variable doesn't exist or suchlike
Thank you a very details and very usefil example
You talk about not using proc's
My need is to do the same thing (steps say 5 which includes a test ) in multiple places on a big switch statement based upon uri.
I can't group the URI together to write this code once and i don't want to duplicate it many times so i thought a call would be the way to do it.
you allude that there are better ways to do it. how would you do that ?
Hi Alex,
Could you please write some pseudo code how the switch statement looks like and where the proc should be executed?
In most cases, you could probably devide your code structure in two destinct parts, the first part parameterizes settings based on conditions (aka. Switch statement assigns variables) and a second part reads parameters and then executes code conditional. This is probably the most used technique...
Instead of using [call] procedures you could use [eval] based macros. The difference between those two is that the [eval] macros are executed in the same execution level and can natively access the varibale from the caller. This is actually a slightly rare used technique...
There are many more options available to avoid the use of TCL procedures. It all depends what you are trying to achive...
Cheers, Kai
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