|
Joined: Jul 2006
Posts: 4,020
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,020 |
It's probably because you don't use a value when adding a item ($$1) to the hash table : /addbot //hadd -s bots $$1 so $hget(table,$2) return the value, which is $null.Your $hfind work because it search in table for an item, not a value (you can search for value with the propriety .data, read the help file) Edit : In the loop of RusselB, only $hget(<table>,%a).item will return something.You should use something like : /addbot //hadd -s bots $$1 1 With this, $hget(bots,host) will return 1 if the host exist, and $null if doesn't.
Last edited by Wims; 09/05/08 12:19 AM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
AWEstun
|
AWEstun
|
Russel's loop worked as he wrote it. I tested it. ???
//var %a = 1, %b = $hget(<table>,0).item | while %a <= %b { echo -a $hget(<table>,%a).item is $hget(<table>,%a) | inc %a }
I see what you are saying about the '1' as the first item in the field for the host, which is the way a table works: 1.2.3.4 1 on a /hget for 1.2.3.4 /hget would return a 'true' thus letting the 'if' continue.
|
|
|
|
Joined: Jul 2006
Posts: 4,020
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,020 |
I don't said that his code doesn't work, i just said the $hget value will be $null with your exemple
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
AWEstun
|
AWEstun
|
I don't said that his code doesn't work, i just said the $hget value will be $null with your exemple Ah.
|
|
|
|
Joined: Aug 2004
Posts: 7,168
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,168 |
Thanks. I just wanted to verify the 6 hosts in the table. They are there.
Do you have any idea why the $hfind works for me, but the $hget doesn't? Post the two codes that you tried.. the $hfind that worked and the $hget that didn't. I'd be willing to bet that you're not supplying $hget with the correct information to get the proper return, but by comparing the two codes, I should be able to tell and, in turn, tell you what you're doing wrong.
|
|
|
|
AWEstun
|
AWEstun
|
[quote]Post the two codes that you tried.. the $hfind that worked and the $hget that didn't. I'd be willing to bet that you're not supplying $hget with the correct information to get the proper return, but by comparing the two codes, I should be able to tell and, in turn, tell you what you're doing wrong.
$2 = 1.2.3.4 Works: if ($hfind(bots,$2,1)) { Doesn't work: if ($hget(bots,$2)) { The Bot table is: bots 1.2.3.4 bots 5.6.7.8 bots 2.3.4.5 bots 6.7.8.9 bots 3.4.5.6 bots 7.8.9.0
|
|
|
|
Joined: Oct 2003
Posts: 3,641
Hoopy frood
|
Hoopy frood
Joined: Oct 2003
Posts: 3,641 |
Then $2 isnt the key
You'd want to fix your hash table to set whatever $2 is as the key so that you can retrieve the data quicker.
Looking at your original posts it seems the HOST is $2, so you'd want to add THAT as the key, not the nickname.
|
|
|
|
AWEstun
|
AWEstun
|
Then $2 isnt the key
You'd want to fix your hash table to set whatever $2 is as the key so that you can retrieve the data quicker.
Looking at your original posts it seems the HOST is $2, so you'd want to add THAT as the key, not the nickname. the variables that get passed in are %nick %host %chan so wouldn't $2 be correct as the key? That's the way I had it. if ($hget(bots,$2)) { ???
|
|
|
|
AWEstun
|
AWEstun
|
Okay here is what I did:
ITEM | DATA --------------- 1.2.3.4 1 5.6.7.8 1 2.3.4.5 1 3.4.5.6 1
So now when I type this on the command line: //echo -s $hget(bots,2.3.4.5) I get this result: 1 Which should let the 'if' execute.
|
|
|
|
AWEstun
|
AWEstun
|
This works and I have a better understanding of hash files now. Originally I thought an item could be used as it's data (i.e. just the item without it's data). Is that even possible with a hash table? So, now if I want to use a hash table for just userhost, there needs to be something in the data field, like the screen name. Right? I.E.
Item | DATA ------------------------------------------------- screenname1 screenname[12345678_12345678@1.2.3.4]
Anyone have any ideas for a simple lil' script to convert a HUGE text file to a hash table/file?
|
|
|
|
Joined: Oct 2003
Posts: 3,641
Hoopy frood
|
Hoopy frood
Joined: Oct 2003
Posts: 3,641 |
"without data" would mean $null for the data value, but you might as well put a value to make it easier to $hget like you did above. 1 is a good choice, as is something like $true. Of course, you could also put the nickname as the data field, that way you could do reverse lookups (reverse lookups are done with $hfind)... this is probably required by your script later on anyway.
Converting a text file depends on what your text file format is like... since text is just text-- you need to define some format to be able to parse it into item / data.
|
|
|
|
AWEstun
|
AWEstun
|
In the text file each line has a userhost:
screenname[12345678_12345678@1.2.3.4]
Convert to hash table format:
screenname screenname[12345678_12345678@1.2.3.4]
This way I can search the hash table by screenname (item) to get all the userhosts (data) that use that screenname.
Though I'm a lil' bit confused as to how to use the host from each of those screenname's (item) userhost (data) and search the hash table for all the screennames that use that host. Like a reverse lookup.
|
|
|
|
AWEstun
|
AWEstun
|
In a hash table, how do you keep the data 'in order' so that it's saved to each item 'uniformly?' Can you you write to specific keys (?) for an item? I.E.
ITEM.......|1........2....3.....4........5........6........DATA --------------------------------------------------------------- screenname1 userhost time chan last_said userhost userhost ... screenname2 userhost .... .... ......... userhost ........ ... screenname3 userhost time chan last_said ........ ........ ...
Does this look right?
|
|
|
|
Joined: Aug 2004
Posts: 7,168
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,168 |
As long as all of the same parameters are passed to the table, they will be stored in the order that you pass them.
|
|
|
|
AWEstun
|
AWEstun
|
Can someone clearify $hget for me? Lets call the hash table info. The uniformity of each item is:
screenname1 userhost time channel last_said
Then if: set %a screenname1
So would $get(info,a%) return 'userhost' or 'userhost time channel last_said'
To retrieve a particular key of an item, like time for screenname1, $get(info,a%,2).item
???
|
|
|
|
Joined: Aug 2007
Posts: 331
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Aug 2007
Posts: 331 |
$hget returns everthing on an item
so: example: hadd Table item test item name blah blah blah $hget(Table,Item) returns: test item name blah blah blah
|
|
|
|
AWEstun
|
AWEstun
|
Thanks.
I have a 10,000+ text file with userhostmasks. I need help with reading it into a hash table called iptracker. I understand how to /hmake -s iptracker 1000 | /hadd -s iptracker $nick[12345678_12345678@1.2.3.4] | hname/hsave -so text iptracker.hsh | /hload -so iptracker iptracker.hsh | /hfree iptracker | etc.
Each line in the text file is in the format: screenname[12345678_12345678@1.2.3.4
/hmake -s iptracker 1000 /hsave -so iptracker iptracker.hsh
//var %a = 1, %b = $read(iptracker.txt,1) | echo -s %a %b | while %a <= %b { var %c = $read(iptracker.txt,%a) | echo -s %c | var %nick = $gettok(%c,1,91) | /hadd -s iptracker %nick %c | inc %a | unset %nick %c }
This works... but is there a better way?
RusselB's example to read a hash file:
//var %a = 1, %b = $hget(<table>,0).item | while %a <= %b { echo -a $hget(<table>,%a).item is $hget(<table>,%a) | inc %a }
Fixed:
//var %a = 1, %b = $hget(<table>,0).item | while %a <= %b { echo -a $hget(<table>,%a).item is $hget(<table>,%a).data | inc %a }
|
|
|
|
AWEstun
|
AWEstun
|
$hget returns everthing on an item
so: example: hadd Table item test item name blah blah blah $hget(Table,Item) returns: test item name blah blah blah iptracker screenname screenname[12345678_12345678@1234] $hget(iptracker) returns: iptracker %hget(iptracker,screenname) returns: screenname[12345678_12345678@1.2.3.4] %hget(iptracker,1).item returns: screenname[12345678_12345678@1.2.3.4]
|
|
|
|
AWEstun
|
AWEstun
|
On second thought I'm not so sure it's a good idea to strip the nick off the user userhostmask and use that for the item. I'm reconsidering just using the whole userhostmask as the item, but then what would I use for the data part?
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
You can use anything for the data. For example: the $ctime of when the data was added, or just the nick, or simply a 1 to indicate TRUE.
-genius_at_work
|
|
|
|
|