This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Array exists

Old posts that have not been replied to for several years.
Locked
M
Michiel

Array exists

Post by Michiel »

Hi,

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.

Code: Select all

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...

Thanks,

Michiel
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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:

Code: Select all

putlog "$ipcounter($fullhost)"
Once the game is over, the king and the pawn go back in the same box.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Maybe you didn't make ipcounter global in that proc?
M
Michiel

Post by Michiel »

Ah I might have forgotton that, thanks!

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:

Code: Select all

if {$ipcounter($fullhost) != "1"}
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 :-?
Locked