Check if table element exists


I would like to check if a certain table element exists and then take corresponding action like the following:

if (exists(mytable[“my_dynamic_name”]))

do something
do something else

Can someone give me a hint?

Use "in":

if ("my_dynamic_name" in mytable)


You're looking for 'in'

(Not sure if I am interpreting your question right but here is how I read it)

basically use "in" operator

local my_ip_table : table[addr] of bool ;

local ip: addr =

if ( ip in my_ip_table)
  not found

btw, you can also use "!in" operator too which is rather more handy

if (something !in table)
  initialize it here
  table[something] = Blah;


most of scripts just flat return in membership doesn't exist that helps
eliminate a lot of unneeded run through scripts.

if (ip !in Site::local_nets)

<do rest of the heuristics here for local IPs>

Here is a (rather complicated but) useful example which stretches
above problem with an extended use-case:


Hope this helps. Let me know if you need more clearifications.


Thank you! Exactly what I was looking for