mIRC Home    About    Download    Register    News    Help

Print Thread
#9258 01/02/03 10:48 PM
Joined: Dec 2002
Posts: 204
K
keeker Offline OP
Fjord artisan
OP Offline
Fjord artisan
K
Joined: Dec 2002
Posts: 204
hi,

i am trying to use $hfind to search in a hashtable for all the matches that match a certain word/string of words, and this is the code i come up with:
Code:
 ; simple file searcher
;
alias lsearch {
  var %lsearch $1-
  var %hfound $hfind(filelist,* $+ %lsearch $+ *,0,w).data
  while %hfound > 0 {
    echo -a $hget(filelist,$hfind(filelist,* $+ %lsearch $+ *,%hfound,w).data).data
    dec %hfound
  }
}
 


but for some reason, its is not working, the /echo is coming back will a total of ALL my items. what i need it to do is return all the items which match the word. am i doing this right or have i totally flubbed up? Right now it returns a total of all items in the hash table. here is a sample of what it is returning:

Code:
 i search for neoknight which i know there are 32 entries in the filelist hashtable for neoknight:

it returns:
426 32 times 
i search for junkie in the same hashtable exactly the same way and i know there are 10 items in there relating to junkie

it returns:
426 10 times

hope i explained that right, maybe yall can clean my code a little so i can get it working the way i want

Last edited by keeker; 01/02/03 10:52 PM.

keek: Scots - intr.v. keeked, keekĀ·ing, keeks
To peek; peep.
#9259 02/02/03 02:22 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
That's because you're using the .data property with $hget(). $hget().data exists, but you don't want that: $hget().data works by index, ie
$hget(tablename,N).data => returns the data of the Nth value
if N is 0 or non-numeric, $hget().data returns the total number of items in the table. That's what the "426" you get really is.

Just remove the .data from $hget(), ie use something like
Code:
echo -a $hget(filelist,$hfind(filelist,* $+ %lsearch $+ *,%hfound,w).data)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#9260 02/02/03 02:24 AM
Joined: Dec 2002
Posts: 271
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
well, i added 6 items to a table named test, all 6 items contained a keyword of "test", and it returns all 6 of those items data with pretty much the same code as you gave:

Code:
 lsearch { 
  var %lsearch $1-  
  var -s %hfound $hfind(test,* $+ %lsearch $+ *,0,w).data  
  while (%hfound) {   
    echo -a $hget(test,$hfind(test,* $+ %lsearch $+ *,%hfound,w).data).data   
    dec %hfound 
  }
} 


put the var -s just so i know how many matches it returned....it should work for you, and i did it on mirc 6.03

#9261 02/02/03 05:13 AM
Joined: Dec 2002
Posts: 204
K
keeker Offline OP
Fjord artisan
OP Offline
Fjord artisan
K
Joined: Dec 2002
Posts: 204
thanks qwerty, its working perfectly now smile


keek: Scots - intr.v. keeked, keekĀ·ing, keeks
To peek; peep.

Link Copied to Clipboard