This is a breeze to do in perl…
$string=="blah1-blah2-blah3";
($field1, $field2, $field3) = split(/-/,$string,3);
In TCL there is the split function, but I don’t see any references to assigning the component variables in one line According the tcl.tk man page for split that uses an example of splitting of a passwd file, it seems this is the TCL answer to the PERL example above
set string "blah1-blah2-blah3"
set fields [split $string "-"]
foreach field $fields {
lassign $fields field1 field2 field3
}
Is there no one line way to both split and assign into scalar variables all at once? Is a foreach loop honestly necessary and then another command to do the assignment? Sigh, so tedious
Now on to GetField…this is what I have been using and currently I am stuck with having a separate GetField line of irule for each component field in my delimited scalar string. If there is a way to use GetField to pull and assign 2 or more values from a single delimited string please let me know how. Also what is GetField doing? Is it just an F5 shortcut/wrapper to TCL’s split? I dont see GetField as part of the TCL documentation, but maybe I missed it
The background here is I am using a Proc to do some string work for HTTP_REQUEST and I need the proc to return a scalar delimited value that my HTTP_REQUEST event can then assign each into a variable. Right now I have to do multiple GetField calls on the string, one for each variable I need What is worse is I have a very nice embedded call to the proc inside like this
set newquery "?[getfield [call fully_decode_urx [HTTP::query] 7] "~~~" 2]"
But I certainly don’t want to call the proc twice just to assign more variables and I am loathe to use a variable to get the delimited string back from the proc and then use two separate newline GetField calls to parse that string, sure at least that wouldn’t call the proc twice, but the simplicity of the PERL split is really what I am looking for. If I can do that in TCL supported native or with GetField or some other way I’d love to know how
And of course since variable are locally scoped in a Proc I can’t set them there and then reference them from inside HTTP_REQUEST
Appreciate any advice/suggestions