Solved

Fast array item search and fast file write

Posted on 2004-04-25
2
521 Views
Last Modified: 2007-12-19
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.
0
Comment
Question by:intoxicated
2 Comments
 
LVL 18

Accepted Solution

by:
kandura earned 175 total points
ID: 10912406
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
 

Author Comment

by:intoxicated
ID: 10912589
Hm, very interesting.
Sorry about my english, it's not my first language.
Thanks alot for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Port 80 requests 16 87
perl to convert excel to csv 3 182
Perl modules on linux ec2 3 96
Put query string from URL request -  PERL HTTP Daemon 2 73
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now