mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
While there is a way to count total items in a table, is there a way to count the total number of data values for all items?

While $hget(table,0).item returns the total number of items in the table, you'd think $hget(table.0).data would return the total number of data values in table, but it returns the same as $hget(table,0).item which is the total number of items in the table. So, in order to count the total number of data values for all items, would I have to read in the data value(s) for each item and add $numtok to an on going total?

Code:
set %totitems $hget(table,0).item
set %totitems.org %totitems
while (%totitems) {
  set %a $hget(table,%totitems).item
  set %b $hget(table,%a)
  set %totnumtok(%b,32)
  set %grndtotdata (%grndtotdata + %totnumtok)
  dec %totitems
}
echo -s Table has %totitems.org items with %grndtotdata of data values across all items.


I registered; you should too.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Items = Data values as far as mIRC's concerned. Who is to say that your data values are seperated in any specific way? And how would mIRC count them without reading each separately anyhow? I'm assuming that mIRC keeps an "index" of all items, so total items is as easy as total lines in a file. Total data items (if you mean space separated items or something in the table) takes more work, just like if you wanted total words in a file. You have to loop through and count using $numtok or $gettok.

Of course, if you need that information, you'd probably be better off setting up your table so each item only has 1 piece of data so you can just get $hget(table,0).item.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
As Riamus mentioned, it is easier to have hash table items with one piece of data in each item. If the type of pieces of data in your hash table items is always the same for each item, you could have separate hash tables for each type of data.

Example
$hget(name,$nick)
$hget(address,$nick)
$hget(age,$nick)
etc.

Or you could add suffixes to the items on a single table.

Example:
$hget(table,$+($nick,.name))
$hget(table,$+($nick,.address))
$hget(table,$+($nick,.age))
etc.

If the pieces of data aren't named like that, you could add numbers as suffixes.

Example:
$hget(table,$+($nick,.1))
$hget(table,$+($nick,.2))
$hget(table,$+($nick,.3))
etc.

Obviously, these suggestions may not work in your specific situation, but they are good tips for future reference.

-genius_at_work


Link Copied to Clipboard