adding elements to tables

Vern Paxson vern at ee.lbl.gov
Wed Sep 20 02:30:22 PDT 2000


> How can I add an element to a table, since I get a "run-time error" if I try 
> to index a table with a value which is not in the table (as it is specified in
> the bro language)?

It's not clear to me what you're asking.  If the problem is "how do I add
a value to a table element if the table element might not be present yet",
the answer is to test with the "in" operator:

	if ( foo in my_table )
		my_table[foo] += additional_value;
	else
		my_table[foo] = additional_value;

With the 0.7 release, you'll be able to specify default values for
table entries, so this will look like:

	global my_table: table[foo_type] of count &default = 0;

and then you can add to it using simply

	my_table[foo] += additional_value;

Or are you asking about something different?

		Vern



More information about the Bro mailing list