Forum Discussion

BaltoStar_12467's avatar
Oct 14, 2015

BIG-IP : TCL to match member of set

F5 BIG-IP Virtual Edition v11.4.1 (Build 635.0) LTM on ESXi

There must be a better way :

if { ( $segments_count == 3 ) || ( $segments_count == 4 ) || ( $segments_count == 5 ) } {

if { [expr {$name_first eq "John"}] || [expr {$name_first eq "Greg"}] || [expr {$name_first eq "Brian"}] } {

NOTE: I don't want to use class matches ( as these require external data-group-files )

  • Okay, so a few things:

    Data groups are not all external. You can create internal data groups that also use the *class commands. This is by far the simplest option to achieve what you want for the string values.

    The expr command is generally intended for math, so you don't need it to evaluate a string:

    if { $name_first eq "John" } 
    

    You can do a single expr for multiple integer evaluation:

    set var 4
    if { [expr { ( $var >= 3) and ( $var <= 5 )}] } {
        log local0. "match"
    }
    
  • however it's my understanding that the string comparison operators eq ne are native to the language used inside [expr ] blocks

     

    They are, technically. But TCL is flexible enough that you don't need to be inside an expr to use them, and by convention you'll see most string comparisons throughout DC wikis and posts don't use them either.