mIRC Home    About    Download    Register    News    Help

Print Thread
using $readini() but finding more than one result #241438 22/04/13 05:32 AM
Joined: May 2006
Posts: 98
L
Lloyd_B Offline OP
Babel fish
OP Offline
Babel fish
L
Joined: May 2006
Posts: 98
I'm currently using $readini() with a data file that might have more than one match. Instead of manually going through the entire data file to append the data so the matches are on one line I'd like to find a way to just accumulate the data when the result is shown. Is there a way to do that?

What I'm doing is using $readini() to retrieve a zip code data match and show it on the channel my bot is on. I already have a feature that matches the zip code a user gives and it retrieves the city and state from the data file and displays it. This feature runs fine.

What I'd like to do is do the reverse and have the user enter the city and state and the bot retrieves all the valid zip codes that are related to that specific city and state. Being there's sometimes more than one zip code attached to the city and state there's a couple or more lines. So, I need to have the bot give the extra matches. $readini() only retrieves a single match as does most of the other commands like that.

Is there a way to do read more than one match and append it into a single result without going crazy with lots of code?

I'm still learning coding and I haven't found an easy way to accomplish what I need.

By the way, the reason I don't want to just go through the data and append the zip codes into a single line is because my data file is about 42,000 lines. The process of altering the data would take an excessively long time. That's why I'm looking for a more time effective solution.

I'd deeply appreciate any help anyone could give me.



Lloyd
Re: using $readini() but finding more than one result [Re: Lloyd_B] #241444 22/04/13 12:34 PM
Joined: Jul 2006
Posts: 3,559
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,559
We can guess from your post that you have a section in your ini file with item being zipcode and the data being the state/city, if that's not correct, blame yourself for not giving enough details.

What you are saying means that the way ini files work, you'll have to loop 42000 times over $ini to find all matches for a given state/city, because there is no $inifind or similar.

You can do that, but that's going to be terribly slow for no reason, ini file are just not the tool you want to use, hash table are, note also that moving the data from an ini file to an hash table is done internally by mIRC using the /hload -i function, no need for you to convert anything, here is a little example:
Code:
alias findmatch {
hmake test
hload -i test c:\myinifile.ini mysection
;supposing the ini file structure is like <zipcode>=<city>@<state>, you would use $hfind to find matches:
echo -a there is $hfind(test,mycity@mystate,0,w).data matches
;this means "look in the table 'test' for some data matching (using wildcard) "mycity@mystate"".
;mirc will basically perfom the 42000 iterations of the loop for you.
hfree test
}


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: using $readini() but finding more than one result [Re: Wims] #241453 23/04/13 01:37 AM
Joined: May 2006
Posts: 98
L
Lloyd_B Offline OP
Babel fish
OP Offline
Babel fish
L
Joined: May 2006
Posts: 98
Originally Posted By: Wims
We can guess from your post that you have a section in your ini file with item being zipcode and the data being the state/city, if that's not correct, blame yourself for not giving enough details.


Hehe, yeah, I would have to blame myself if I did that, but you're right, the first ini file has basically a line for each zipcode. It basically goes like this "012345=city, ST". The second file had the opposite "City, ST=012345". However, I had some issues with the data so I changed each line to "city_ST=012345".

I wasn't aware of the hash table stuff, I'm learning something new all the time. I appreciate your time in explaining it and giving the code. I will give it a try and see if I can get it to work that way.


Lloyd