?
Solved

I need a faster solution for searching

Posted on 2002-05-08
5
Medium Priority
?
223 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 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 85

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
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…
Six Sigma Control Plans
Suggested Courses

809 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