A problem during using 'set'

Hi,

I was testing my code written in Bro, and I was noticing some wrong values. When I debugged the code, the following section had the problem (the bold part)

if(vals[index2] == “length”){
local length_vals = split(vals[index2 + 1], /-/);
local lengths: set[count];
print cat("here - prev length = ", |lengths|);
for(index3 in length_vals)
if(length_vals[index3] != “”) add lengths[to_count(length_vals[index3])];
print |lengths|;
} #finished lengths
here is the output.

here - prev length = 0
1
here - prev length = 1
2
here - prev length = 2
3
here - prev length = 3
4
here - prev length = 4
31
here - prev length = 31
34
here - prev length = 34
46
here - prev length = 46
48

It means that whenever I declare local lengths: set[count]. It is not initializing a new ‘set’, but keeps the state of previous set of values entered and updated it. Why is it doing so?
regards,
Asma

And the problem remains same, even if I use ‘table[count] of count’.

regards,
Asma

You aren't assigning a value to the variable, you are only declaring the type of the variable. Try this:

local lengths: set[count] = set();

  .Seth

if(vals[index2] == "length"){
                local length_vals = split(vals[index2 + 1], /-/);
                *local lengths: set[count];*

Contrary to most languages, "local" declarations in Bro persist throughout
the entire function/event handler in which they're declared. They don't
get discarded once the block they're declared in goes out of scope.
I believe this explains the behavior you're encountering

Arguably this should be changed, but doing so would be a fair amount
of work.

    Vern