Forum Discussion

Ger_Hackett_323's avatar
Ger_Hackett_323
Icon for Nimbostratus rankNimbostratus
Sep 19, 2012

Increment Array Element

Hi,

 

Is there any neat way to increment any array element. At the moment I’m doing:

 

 

set TempVar $::MyArray($some_index)

 

incr TempVar

 

set ::MyArray($some_index) $TempVar

 

unset TempVar

 

 

Thanks,

 

Ger.

 

3 Replies

  • You could potentially one-line it with something like this:

     

     

    array set TempVar { var 1 }

     

     

    set TempVar [incr TempVar(var)]

     

     

  • You could potentially one-line it with something like this:

     

     

    array set TempVar { var 1 }

     

     

    set TempVar(var) [incr TempVar(var)]

     

     

  • Using a global array will disable CMP. You might want to check if using a table will work for your scenario as it's CMP compatible:

     

     

    https://devcentral.f5.com/wiki/iRules.CMPCompatibility.ashx

     

    https://devcentral.f5.com/wiki/iRules.table.ashx

     

     

    Aaron