Solved

I need a faster solution for searching

Posted on 2002-05-08
5
196 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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