Forum Discussion

Chris_Phillips's avatar
Chris_Phillips
Icon for Nimbostratus rankNimbostratus
Aug 03, 2006

Scoping variables

Hi,

 

 

I had a thread recently which lead to this wiki entry http://devcentral.f5.com/wiki/default.aspx/iRules/DestinationSnatUsingDNS.html and one instance of this iRule works fine, however as every variable used there is global, another instance requires the change of every variable name involved, otherwise they overwrite each other. This is obviosuly fairly horrible, yet if we define the variable within the RULE_INIT block that variable is lost outside of there once its completes its execution.

 

 

is there a nicer way that somehow falls inbetween these two situations?

 

 

Thanks

 

 

Chris
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Well, it appears as though the only variable in that example that truly needs to be defined globally is the count variable. Since the rest are statics, they could be set for just that particular iRule, and things would be fine.

     

     

    This would make it so all you had to do was change the name of the "count" variable between iRule permutations, which would be at least somewhat of an improvement.

     

     

    Colin