?
Solved

I need a faster solution for searching

Posted on 2002-05-08
5
Medium Priority
?
218 Views
Last Modified: 2010-03-05
Hi ,

I'm currently doing a search using the method below and the spelling.txt file contains 20,000 lines. And my string $FullName is like "Mike_Abbas". When I run the search it's taking a very long time for each names and I have approximately 20,000 names. Any other better ways??

open F,'<C:\Nick\SingTelVoicePortal\Perl\spelling.txt';
@lines = <F>;
$num_match = grep /^$FullName$/i, @lines;
print $num_match;
0
Comment
Question by:n_chai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Accepted Solution

by:
japhyRPI earned 400 total points
ID: 6998066
Don't read the entire file at once, and don't use a regex.

  my $matches = 0;
  open FILE, "< $path" or die "can't read $path: $!";
  while (<FILE>) {
    chomp;
    $matches++ if $_ eq $FullName;
  }
  close FILE;
0
 
LVL 5

Expert Comment

by:amandeep
ID: 6999816
n_chai,

Try this:

my $num_match= 0;
my $FullName = "Mike_Abbas";
open(F,'<C:\Nick\SingTelVoicePortal\Perl\spelling.txt') or die "can't open file: $!";
while (<F>) {
   chomp;
   $num_match++ if(uc($_) eq uc($FullName));
}
close(F);
print $num_match;

0
 
LVL 8

Expert Comment

by:jhurst
ID: 7000314
Assuming use of a decent OS, such as unix:

$num_match=`grep -i \"$FullName\" yourFileName |wc -l`;

Should not be true but grep and wc are very efficient and the pipe lets them run in parallel.
0
 
LVL 84

Expert Comment

by:ozo
ID: 7000355
while( <FILE> ){
    chomp;
    $matches{uc $_}++;
}
foreach $FullName ( 'Mike_Abbas', 'n_chai' ...  ){
    print "$FullName: $matches{uc $FullName}\n";

}
0
 
LVL 6

Expert Comment

by:andreif
ID: 7000639
n_chai, you have a number of open questions where the answer is given. Please, take a look at those topics. If you didn't get answer, you can alwais ask more questions in that topics, but it's not very good idea to ignore given comments
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans

770 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