Solved

I need a faster solution for searching

Posted on 2002-05-08
5
177 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
5 Comments
 
LVL 1

Accepted Solution

by:
japhyRPI earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
while( <FILE> ){
    chomp;
    $matches{uc $_}++;
}
foreach $FullName ( 'Mike_Abbas', 'n_chai' ...  ){
    print "$FullName: $matches{uc $FullName}\n";

}
0
 
LVL 6

Expert Comment

by:andreif
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

9 Experts available now in Live!

Get 1:1 Help Now