Fast array item search and fast file write

Hey everyone,

    I do have a couple of questions and I'm ready to loose some points.
    1 problem: I need a -fast- code to look for a substring in an array of strings. The strings are website names, so the strings may contain [ .,-,a-zA-Z, / ] symbols. The script should check if a  given word is a part (sub string or equal) of any string in array. I wrote a perl script to do it, but I'm afraid it'll be way too slow for large number of searches.

     2 problem: similar. fast way to flush results into a file. Should I keep one file open all the time the script is running, so I can write to it anytime, or is there a better way to do this?

    Any advice greatly appreciated.
intoxicatedAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
kanduraConnect With a Mentor Commented:
1) There's a new article on perl.com which might be of interest to you: http://www.perl.com/pub/a/2004/04/08/bloom_filters.html
If you're only interested in knowing whether there is a match, then this is a very efficient solution.
But if you also need to know which items in your array matched, then I don't think there is any other way than to iterate over the array and checking for a match.

2) It depends on your requirements. Of course it isn't very efficient to open and close a file very often. But it also not very efficient to do lots of little writes to a file. The general answer would be to collect as much of your output as possible, and write it out in one large chunk, but you'd have to balance that with the memory usage. Note that this assumes that by "fast" you mean "don't spend a lot of time with the file".
If you mean "fast" as in "make new data available at the earliest possible moment", then your description would seem to fit best.

0
 
intoxicatedAuthor Commented:
Hm, very interesting.
Sorry about my english, it's not my first language.
Thanks alot for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.