mIRC Homepage
Posted By: AWEstun Hash Table: Counting data in an item - 04/06/08 01:36 AM
In a hash table how do I go about counting the data in an item, so that I can perform a task on each piece of data.
What do you mean by 'counting' the data? You can perform any regular string actions on hash table data after you reference it using $hget or $hfind.

-genius_at_work
Posted By: AWEstun Re: Hash Table: Counting data in an item - 04/06/08 01:52 PM
Originally Posted By: genius_at_work
What do you mean by 'counting' the data? You can perform any regular string actions on hash table data after you reference it using $hget or $hfind.

-genius_at_work


Well lets say there are data (IP's) for an item name. Each item name has a different number of data. I want to perform a task or each one of those data, but how do I know how many data are there for each item name? For example:

itemname1 1234 2434 6234 6346
itemname2 3456
itemname3 6345 2344

How do I know how many times to run the task for each item name, by data count?
You need to locate the hash item and then use the token identifiers to access each section of the data from that hash item.

Example:
Code:

var %data = $hget(hash1,item3)
echo -a number of tokens: $numtok(%data,32)
echo -a first token: $gettok(%data,1,32)
%data = $puttok(%data,ABCD,1,32)
echo -a new first token: $gettok(%data,1,32)
hadd hash1 item3 %data



Example:
Code:

var %c = 0, %cc = $hget(hash1,0).item
  while (%c < %cc) {
    inc %c
    var %item = $hget(hash1,%c).item
    var %data = $hget(hash1,%item)

    var %i = 0, %ii = $numtok(%data,32)
    while (%i < %ii) {
      inc %i
      echo -a Item: %item  Data %i $+ : $gettok(%data,%i,32)
    }
  }
}



untested


-genius_at_work
Posted By: AWEstun Re: Hash Table: Counting data in an item - 04/06/08 02:27 PM
Thanks. $numtok() is what I was looking for. Then from that the tokens can be accessed with $gettok().
© mIRC Discussion Forums