I’m having a hard time finding documentation for this that is specific to Big-IP v 11, but it looks like iRules are based on Tcl 8.4.6. The command lassign wasn’t introduced in Tcl until v8.5. This would explain why the command isn’t listed in the disabled Tcl Commands list - it didn’t exist.
Since I’m getting the following error, I figure either lassign really isn’t supported, or I’m using it wrong:
error: line 392: [undefined procedure: lassign] [lassign $fields \ result cn goAgent goPolicyHierID goSalesID]
So, I’m hoping someone can help me devise an alternative method here:
set content [HTTP::payload]
if { $content ne “” } { log local0. “HTTP::Payload set”}
split into records in new lines
set records [split $content “\n”]
iterate over the records
foreach rec $records { split into fields on colons set fields [ split $rec “:” ]
It looks like that might work - lassign would have let me parse through each instance of $fields and set each as a variable with it’s own name.
I think I can use lindex to select records one at a time based upon their location in the list, but I’m not clear on how to then set that record as a new variable.
For a little context - I’m trying to read an http page that has a list of strings (currently seperated by colons, but could be seperated by anything.) Then, once I have that list, I want to take each item and set it as an individual variable, which I’m then going to store and use elsewhere. So, really, I just need a decent way to read the list and store the values found there.
I’m not clear on how to then set that record as a new variable. you mean there are multiple lines in the payload and you want to keep them all, don’t you? if so, may we add it into table (1 subtable per line)?
It looks like the tables are referred to as ‘session tables’ --- does this mean that they are persistent with the users session?yes but actually, it is globally shared data among all connection and tmm.
The keys and variables may change without notification - so hardcoding them in as a static::field is less than ideal. The initial data is already stored as a variable (let’s say it’s $attributes).
We can split the $attributes into records based on “|”, and then split the records into fields based upon “=”.
Where I’m getting stumped is populating a table with those fields. How do I get it to look something like this:
key | value
$field1 | $field2
$field3 | $field4 etc.
I can then pull the data from the table, because I’ll know the key name that I’m looking for when I need to pull it back from the table- so I can do a
table lookup $field3
for example, substituting the value of $field3 and getting the $field4 value returned.