http://qs321.pair.com?node_id=572961

SteveS832001 has asked for the wisdom of the Perl Monks concerning the following question:

My company has to use a Do Not Call list that is generated for us by another company and they list all the numbers in text files.

Example
9991112222
9991112223
9991112224

We Have 3 area codes that we have lists for. So that means we have 3 text files that have a grand total of, a little over 2 million phone numbers
They are wanting me to create a program with a gui that would search the text files for the number that they want to search for. Which I have created, But the program uses a lot of memory and a lot of the processor and takes around 15-20 seconds to fail which takes the logest since it has to search the most.
My question is how do I make this instant or faster. 2 or 3 Seconds. I have tried slurping the files into an array and searching that way but it only improves it by a second or two.
use Tk; use Tk::Dialog; use Win32::GUI; $count = 1; my $mw = MainWindow->new; my $c = $mw->Canvas( -width =>400, -height=>200, -background => "white"); $c->pack; ############################Main window $map = $mw->Photo ( -file => 'bos.gif', -height => 40, width => 400 ); $map_label = $mw->Label ( -image => $map); $map_label->place(-x =>0, -y => 0); ############################Inserts the bank of sullivan image $quit = $mw->Button( -text => "Quit", -padx => "8", -command => \&Quit); $quit->place(-x => 350, -y => 180); ###########################adds the quit button $Find = $mw->Button( -text => "Search", -command => \&Search); $Find->place(-x => 300, -y => 180); ################################################ $lab = $mw->Label ( -text => "Enter Phone Number", -background => "white" ); $lab->place(-x => 5, -y => 50); ##############################Label $Entry = $mw->Entry( -textvariable => \$num, -background => "white" ); $Entry->place(-x => 5, -y => 68); ##################################Entry $text = $mw->Text( -height => 5, -width => 55, -wrap => char ); $text->place(-x => 5, -y => 90); ################################# $labWarning = $mw->Label ( -text => 'Example XXX - XXX - XXXX', -background => "white" ); $labWarning->place(-x => 140, -y => 68); $index = 1; ####################################### sub Quit { my $d = $mw->Dialog( -text => "Are you sure you want to quit?", -buttons => ["Yes", "No"]); my $answer = $d->Show(); close(UNLOCK); exit if ($answer eq "Yes") } sub Search { $found = 0; @number = split(/-/, $num); $file1 = 'f:\donotcall\314.txt'; $file2 = 'f:\donotcall\573.txt'; $file3 = 'f:\donotcall\636.txt'; $file4 = 'f:\donotcall\Cell.txt'; open(FIRST, "<$file1") or die "Can't open File $!"; open(SECOND, "<$file2") or die "Can't open File $!"; open(THIRD, "<$file3") or die "Can't open File $!"; open(Cell, "<$file4") or die "Can't open File $!"; $text->insert (0.1, "Searching\n"); $mw->update(); if ($number[0] == 314) { while(my $line = <FIRST>){ if($line =~ /$number[0]$number[1]$number[2]/) { close(FIRST); close(SECOND); close(THIRD); close(Cell); $found = 1; } } } if ($number[0] == 573) { while(my $line = <SECOND>){ if($line =~ /$number[0]$number[1]$number[2]/) { close(FIRST); close(SECOND); close(THIRD); close(Cell); $found = 1; } } } if ($number[0] == 636) { while(my $line = <THIRD>){ if($line =~ /$number[0]$number[1]$number[2]/) { close(FIRST); close(SECOND); close(THIRD); close(Cell); $found = 1; } $count++; if ($count == 2000) { $mw->update(); $count = 0; } chomp($line); $text->insert(0.1, "$line "); } } while(my $line = <Cell>){ if($line =~ /$number[0]$number[1]$number[2]/) { close(FIRST); close(SECOND); close(THIRD); close(Cell); $found = 1; } } if ($found == 1) { $text->insert ("0.1", "The number ($num) was found\n"); $text->insert ("0.2", "DO NOT CALL\n"); $text->insert ("0.3"," \n"); $text->insert ("0.4"," \n"); $text->insert ("0.5"," \n"); } else { $text->insert ("0.1", "The number ($num) was NOT found\n"); $text->insert ("0.2", " \n"); $text->insert ("0.3", " \n"); $text->insert ("0.4", " \n"); $text->insert ("0.5", " \n"); } } MainLoop;