$hfind

From Scriptwiki
Revision as of 22:27, 20 November 2005 by Doomie (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Searches table for the Nth item name which matches text. Returns item name.

$hfind(name/N, text, N, M)[.data]

If you specify the .data property, it searches for a matching data value.

M is optional, and can be:

MExplanation
nnormal text comparison (default if M isn't specified)
wtext is wildcard text
Whash table item/data is wildcard text
rtext is regular expression
Rhash table item/data is regular expression

Note that if you specify N = 0, it will return the total amount of matching items (see the second example below).

Example

At first, we need a hashtable for all examples, so lets make one:

; have a nice alias called makehash for it
alias makehash {
 ; here we actually make the hashtable
 hmake testhash 100
 ; now lets put data in it
 hadd testhash Dana Dana@staff.quakenet.org
 hadd testhash user1 user1@random.host
 hadd testhash user2 user2@another.host
}

The first example will just search for user1@random.host and returns the item (user1):

echo -a $hfind(testhash,user1@random.host,1).data

The next example will loop through all data's containing *user* and return the item and data.

user1 => user1@random.host

user2 => user2@another.host

var %i = 1
; let's start the looping. $find(testhash,*user*,0,w).data returns the total amount of found items.
while (%i <= $hfind(testhash,*user*,0,w).data) {
 ; this echos it to the active window. $hget(testhash,$hfind(testhash,*user*,%i,w)) returns
 ; the data of the found item.
 echo -a $hfind(testhash,*user*,%i,w) => $hget(testhash,$hfind(testhash,*user*,%i,w))
 ; increase the looping-variable
 inc %i
}