Here's a really simple way to do lookups by name
Code:
/*
A list of items to hash, might be read from a file or somewhere else
fruit => apple
string+-with.,illegalvarnamechars => banana
vegetable => carrot
*/
;create a unique valid var name for the key
;the []'s are just to make it look like a hash/array lookup
key := Hash("fruit")
items[%key%] = apple
key := Hash("text+-with.,illegalchars")
items[%key%] = banana
key := Hash("vegetable")
items[%key%] = carrot
;find the item
key := Hash("text+-with.,illegalchars")
value := items[%key%]
msgbox %value%
return
; generate uniq ids
; this function returns a reversible representation of a string that
; obeys ahk's rules for variable names
Hash(k)
{
loop, parse, k,
{
a := Asc(A_LoopField)
hashed_key = %hashed_key%$%a%
}
return %hashed_key%
}
This way of working is dependant upon the max length of ahk variables and upon the way ahk looks up variable names, which at one point was very slow.
See
http://www.autohotkey.com/forum/viewtopic.php?t=3004&postdays=0&postorder=asc&highlight=hash&start=0
for more info
I'm not sure what resulted from this discusison. Hopefully this kind of code
works much quicker than it used to.