Reputation: 2305
I'm coding an iRule on our F5 server but I'm a complete beginner when it comes to TCL.
I have a HTTP::host
variable that contain a hostname in the following format: application-dev.com
All I'm trying to do is split this string where the hyphen occurs and set the first and second sections to separate variables. So I would end up with this:
variable1 = application
variable2 = dev.com
I've gotten this far:
set hostSections [split [HTTP::host] "-"]
But can't find any information on how to assign the sections to seperate variables
Upvotes: 0
Views: 2234
Reputation: 71538
You can use lindex
(list index) for older versions of Tcl:
set variable1 [lindex $hostSections 0]
set variable2 [lindex $hostSections 1]
Since lists are 0-indexed, 0
will indicate the first element of the list.
In Tcl 8.5 and later, you can use lassign
which makes things shorter:
lassign [split [HTTP::host] "-"] variable1 variable2
Both ways stores the values in the variable names variable1
and variable2
.
Upvotes: 1