Forum Discussion
ichalis_37981
Dec 13, 2011Historic F5 Account
The EVAL command
Hi all,
I am testing the eval command and want to generate an error if my input script contains an error. My test code is as follows:
set cmd "if { \[HTTP::uri\] starts_with \"/h...
spark_86682
Apr 19, 2012Historic F5 Account
It's more that eval and {*} do different things. Eval takes a string and executes it as a command. {*} is used to expand a Tcl list into separate arguments ("stringifying" it, essentially), typically for use in calling a command.
For example, if you had a variable called $headers which was a Tcl list of header names and values, which looked like:
{ Set-Cookie "foo=bar" Set-Cookie "baz=quux" X-Server "BIG-IP iRule" }
you might want to do something like:
HTTP::respond 302 Location http://new.example.com $headers
to craft an HTTP response with all of those headers. But that wouldn't work, because Tcl would pass in those headers as one big parameter, confusing the HTTP::respond command. With {*}, you could make it work:
HTTP::respond 302 Location http://new.example.com {*}$headers
which would be the same as:
HTTP::respond 302 Location http://new.example.com Set-Cookie "foo=bar" Set-Cookie "baz=quux" X-Server "BIG-IP iRule"
However, the {*} syntax was introduced in Tcl 8.5, and BIG-IP is still using Tcl 8.4. So you need to use eval as a workaround:
eval "HTTP::respond 302 Location http://new.example.com $headers"
This will expand the $headers variable as a string, and parse the contents as separate arguments to the HTTP::respond command.
So eval is an old command, but no more than the rest of Tcl. 🙂
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