Small question (I searched the forums but nothing really came up / helped):
I'm creating a small script that has to count unique hosts. Now, I've never really gotten info exists to work for arrays. I looked up a few examples and mine seems correct. However, the code below always gets past the if statement; even if ipcounter($fullhost) DOES exist. I'd like to know how exactly my if statement will only continue if it doesn't already exist.
if {![info exists ipcounter($fullhost)]} {
set ipcounter($fullhost) "1"
putlog "$fullhost" # <-- to help me see its counting the same host multiple times
incr upcounter
}
I've also tried array exists but that did exactly the same...
The "info exists" should give the right answer, the thing is if you have called globaly the "ipcounter" variable inside your proc (if any) and also it should be:
Edit: I added a global for ipcounter but it still gets past the if statement every time, couting clones multiple times. I also tested by making the if statement:
but obviously it won't work because when it gets to a specific host for the first time it hasnt been set yet (there is no info in that var, it cannot be read, needing info exists). I'm lost