Background:
Windows environment;
using SAMIE for regressive testing of website;
depending upon number of choices selected, a run can take over 30 min;
disconcerting to QC folks to see nothing for half an hour;
This code:
only the "Start testing" and "Exit" buttons are live.
When the following code is run from the command line, click on Start Testing. Information will be printed to the cmd box and only upon completion will the inserts appear in the ROText widget.
The code is looking for 10 digit prime numbers. Website to download numbers is in comments.
Appreciate the help.
# perl_tk_lap_notebook_tek.pl
use Tk::NoteBook;
use Tk;
use Tk::LabFrame;
require Tk::ROText;
#basic notebook from
#
my $main = tkinit;
my $citySelected = "";
our $data_preferences = "";
$main->geometry('+200+200');
$mf = $main->Frame;
$main->Button(-text=>'Exit',
-command=>sub{exit })->pack(-side=>'left');
$nb = $mf->NoteBook(-width=>300);
$nb1 = $nb->add("LAP", -label=>"Page 1");
$nb2 = $nb->add("page2", -label=>"Page 2");
$nb3 = $nb->add("page3", -label=>"Page 3");
$nb4 = $nb->add("page4", -label=>"Page 4");
my $lb_1_1 = $nb1->Listbox(-width =>15,
-height =>10,
)->pack(-side=>'left',
-padx =>3,
-anchor=>'n');
# ========= data ========
my $numCol_city = 3;
my @city_array = ([0,1,2],
["city 1","city 2","city 3"]
);
my @preference_array = ([0,1,2,3,4],
["choice 1","choice 2","choice 3","choice 4","choice 5"]
);
# ========= data end ========
for (my $i=0; $i<$numCol_city;$i++)
{
$lb_1_1 -> insert('end',"$city_array[1][$i]");
}
my $b1 = $nb1->Button(-text=>'Select city',
)->place(-x => 1, -y => 180);
my $b2 = $nb1->Button(-text=>'Select preferences',
)->place(-x => 1, -y => 210);
my $b3 = $nb1->Button(-text=>'Start testing',
)->place(-x => 1, -y=>240);
$b3->configure(-command=>[\&start_test,$b3]);
my $lb_2_1 = $nb1->Listbox(-width =>15,
-height =>15,
-selectmode=>'multiple')->pack(
-side=>'top',
-anchor=>'nw');
my $numCol_pref = 9;
for (my $j=0; $j< $numCol_pref; $j++)
{
$lb_2_1 -> insert('end',"$preference_array[1][$j]");
}
our $t = $nb1->Scrolled("ROText")->pack(-side =>'left',-padx=>50,
-fill => 'both',-expand=>1,-anchor=>'w');
$nb->pack;
$mf->pack;
MainLoop;
sub start_test
{
# the following is finding possible 10 digit prime numbers in a sequence.
# values of pi can be found at
# values of e can be found at
# save the file as a single line string after the decimal point
$file = 'c:/e_many.txt';
open(FH,$file)or die "could not open log file:#!";
$line = <FH>;
close(FH);
$i=0;
while ($i<120)
{
$sub_10 = substr($line,$i,10);
$rev = reverse($sub_10);
$first = substr($rev,0,1);
$flag = 0;
#print "$sub_10 --- $first\n";
if($sub_10 == 8182845904) # 10 digits from e
{
print "Found 8182845904 for i = $i \n";
$| = 1;
$t -> insert('end',"Found 8182845904 for i = $i \n");
}
if($sub_10 == 8747135266) # 10 digits from e
{
print "Found 8747135266 for i = $i \n";
$| = 1;
$t -> insert('end',"Found 8747135266 for i = $i \n");
}
if ($first =~ /[0 2 4 5 6 8]/ )
{
# print "ignore\n";
$flag = 1;
}
else
{
# print "$first, let us find out about $sub_10\n";
for ($j = 1; $j < 500000; $j++)
{
$divide_by = ($j*2 + 1);
#print "divide by : $divide_by\n";
$rem = $sub_10%$divide_by;
if ($rem == 0)
{
# print "$sub_10 can be divided by $divide_by\n";
$flag = 1;
next;
}
# if ($flag == 0)
# { print "$sub_10 might be prime\n"; }
}
}
if ($i == 0)
{
print "$i --- $sub_10, before prime\n";
$t -> insert('end',"$i --- $sub_10, before prime\n");
}
if ($i == 41)
{ print "$i --- $sub_10, \n";
$t -> insert('end',"$i --- $sub_10, \n");
}
if ($i == 42)
{
print "$i --- $sub_10, \n";
$t -> insert('end',"$i --- $sub_10, \n");
}
if ($flag == 0)
{
print "$i -- $sub_10 might be prime\n";
$t -> insert('end',"$i - $i- $sub_10 might be prime\n");
}
$| = 1;
$i++;
}
print "Finished\n";
$t ->insert('end',"Finished\n");
} # end of sub start_test