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

I've written the following code and was wondering if there's a shorter way of writing the same code using a for loop to create my slots.

Thanks

#!/usr/local/bin/perl5 -w require Tk; use Tk; my $Version="1.0"; my @sernums= ("", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", ""); my @partnums= ("", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", ""); # Create main window my $width = 900; my $height = 680; my $main = MainWindow->new(); $main->minsize( ($width, $height)); $main->maxsize( ($width, $height)); $main->title(" SanDisk SFT1"); #$main->setIcon(-file => 'PliantLogo.ico'); $main->configure(-background=>'gray'); #cyan my $menu_bar = $main->Frame(-relief=> 'groove', -borderwidth=> 3, -background=> 'blue', #purple )->pack('-side'=> 'top',-fill=> 'x'); my $file_mb = $menu_bar->Menubutton(-text => 'File', -background => 'blue', #purple -activebackground => 'blue', -foreground => 'white', )->pack(-side=> 'left'); $file_mb->command(-label => 'Exit', -activebackground => 'blue', -command => sub{$main->destroy}); my $help_mb = $menu_bar->Menubutton(-text=> 'Help', -background => 'blue', #purple -activebackground => 'cyan', -foreground => 'white', )->pack(-side=> 'right'); $help_mb->command(-label => 'About', -activebackground => 'blue', -command => \&about_txt); $help_mb->separator(); $help_mb->command(-label => 'Help', -activebackground => 'blue', -command => \&help_txt); #Build the innards my $statusline = $main->Frame(-borderwidth => 3, -relief => 'groove', -background => 'purple')->pack(-side => 'top'); my $status = $statusline->Label(-width => $width, -height => 0, -foreground => 'white', -background => 'purple')->pack(); my $line1 = $main->Frame(-borderwidth => 3, -relief => 'groove', -background => 'gray')->pack(-side => 'top'); my $row1info = $line1->Label(-text => "Slots 01 - 04", -width => $widt +h, -height => 0, -foreground => 'black', -background => 'gray')->pack(); my $row1 = $main->Frame(-background => 'cyan',)->pack(-side => 'top', +-fill => 'x');
################### Labels ################### my $descriptionrow1 = $row1->Frame(-background => 'cyan',)->pack(-side + => 'left', -pady => 9, -padx => 8); my $t1 = $descriptionrow1->Label(-text => 'Serial Number ', -backgroun +d => 'cyan',)->pack(); $t1 = $descriptionrow1->Label(-text => 'Part Number', -background => ' +cyan',)->pack(); $t1 = $descriptionrow1->Label(-text => 'Status', -background => 'cyan' +,)->pack(); #################### Slot 01 #################### my $slot1 = $row1->Frame(-background => 'cyan',)->pack(-side => 'left' +, -pady => 2, -padx => 15); my $descSlot1 = $slot1->Label(-text => 'Slot 01', -background => 'cyan +')->pack(); #my $sernumSlot1 = $slot1->Entry(-width => 22, -background => 'white', + -textvariable => \$sernums[1], -validate => 'key', -validatecommand +=> sub {$_[1] =~ /[0-9]/}, -invalidcommand => sub {$main->bell})->pac +k(); #my $sernumSlot1 = $slot1->Entry(-width => 22, -background => 'white', + -textvariable => \$sernums[1], -validate => 'focusout', -validatecom +mand => sub {return($_ =~ /\d{8}/)}, -invalidcommand => sub {$main->b +ell})->pack(); my $sernumSlot1 = $slot1->Entry(-width => 22, -background => 'white', +-textvariable => \$sernums[1], -validate => 'focusout', -validatecomm +and => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack(); my $partnumSlot1 = $slot1->Entry(-width => 22, -background => 'white', + -textvariable => \$partnums[1], -validate => 'focusout', -validateco +mmand => \&validatePartNum, -invalidcommand => \&invalidPartNum)->pac +k(); my $statusSlot1 = $slot1->Label(-text => '1dormant', -background => 'w +hite', -width => 19, -relief => 'groove', -borderwidth => 3)->pack(-a +nchor => 'center'); my $goSlot1 = $slot1->Button(-width => 10, -height => 1, -text => 'Sta +rt', -background => 'gray', -command => \&compute)->pack(-side => 'to +p', -anchor => 'center'); #################### End Slot 01 #################### #################### Slot 02 #################### my $slot2 = $row1->Frame(-background => 'cyan',)->pack(-side => 'left' +, -pady => 2, -padx => 15); my $descSlot2 = $slot2->Label(-text => 'Slot 02', -background => 'cyan +')->pack(); my $sernumSlot2 = $slot2->Entry(-width => 22, -background => 'white', +-textvariable => \$sernums[2], -validate => 'focusout', -validatecomm +and => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack(); my $partnumSlot2 = $slot2->Entry(-width => 22, -background => 'white', + -textvariable => \$partnums[2], -validate => 'focusout', -validateco +mmand => \&validatePartNum, -invalidcommand => \&invalidPartNum)->pac +k(); my $statusSlot2 = $slot2->Label(-text => '2dormant', -background => 'w +hite', -width => 19, -relief => 'groove', -borderwidth => 3)->pack(-a +nchor => 'center'); my $goSlot2 = $slot2->Button(-width => 10, -height => 1, -text => 'Sta +rt', -background => 'gray', -command => \&compute)->pack(-side => 'to +p', -anchor => 'center'); #################### End Slot 02 #################### #################### Slot 03 #################### my $slot3 = $row1->Frame(-background => 'cyan',)->pack(-side => 'left' +, -pady => 2, -padx => 15); my $descSlot3 = $slot3->Label(-text => 'Slot 03', -background => 'cyan +')->pack(); my $sernumSlot3 = $slot3->Entry(-width => 22, -background => 'white', +-textvariable => \$sernums[3], -validate => 'focusout', -validatecomm +and => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack(); my $partnumSlot3 = $slot3->Entry(-width => 22, -background => 'white', + -textvariable => \$partnums[3], -validate => 'focusout', -validateco +mmand => \&validatePartNum, -invalidcommand => \&invalidPartNum)->pac +k(); my $statusSlot3 = $slot3->Label(-text => '3dormant', -background => 'w +hite', -width => 19, -relief => 'groove', -borderwidth => 3)->pack(-a +nchor => 'center'); my $goSlot3 = $slot3->Button(-width => 10, -height => 1, -text => 'Sta +rt', -background => 'gray', -command => \&compute)->pack(-side => 'to +p', -anchor => 'center'); #################### End Slot 03 #################### #################### Slot 04 #################### my $slot4 = $row1->Frame(-background => 'cyan',)->pack(-side => 'left' +, -pady => 2, -padx => 15); my $descSlot4 = $slot4->Label(-text => 'Slot 04', -background => 'cyan +')->pack(); my $sernumSlot4 = $slot4->Entry(-width => 22, -background => 'white', +-textvariable => \$sernums[4], -validate => 'focusout', -validatecomm +and => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack(); my $partnumSlot4 = $slot4->Entry(-width => 22, -background => 'white', + -textvariable => \$partnums[4], -validate => 'focusout', -validateco +mmand => \&validatePartNum, -invalidcommand => \&invalidPartNum)->pac +k(); my $statusSlot4 = $slot4->Label(-text => '4dormant', -background => 'w +hite', -width => 19, -relief => 'groove', -borderwidth => 3)->pack(-a +nchor => 'center'); my $goSlot4 = $slot4->Button(-width => 10, -height => 1, -text => 'Sta +rt', -background => 'gray', -command => \&compute)->pack(-side => 'to +p', -anchor => 'center'); #################### End Slot 04 #################### my $line2 = $main->Frame(-borderwidth => 3, -relief => 'groove', -background => 'gray')->pack(-side => 'top'); my $row2info = $line2->Label(-text => "Slots 04 - 08", -width => $widt +h, -height => 0, -foreground => 'black', -background => 'gray')->pack(); #################### Row 2 Frame #################### my $row2 = $main->Frame(-background => 'cyan',)->pack(-side => 'top', +-fill => 'x'); my $descriptionrow2 = $row2->Frame(-background => 'cyan',)->pack(-side + => 'left', -pady => 9, -padx => 8); my $t2 = $descriptionrow2->Label(-text => 'Serial Number ', -backgroun +d => 'cyan',)->pack(); $t2 = $descriptionrow2->Label(-text => 'Part Number', -background => ' +cyan',)->pack(); $t2 = $descriptionrow2->Label(-text => 'Status', -background => 'cyan' +,)->pack(); #################### Row 2 Frame #################### #################### Slot 05 #################### my $slot5 = $row2->Frame(-background => 'cyan',)->pack(-side => 'left' +, -pady => 2, -padx => 15); my $descSlot5 = $slot5->Label(-text => 'Slot 05', -background => 'cyan +')->pack(); my $sernumSlot5 = $slot5->Entry(-width => 22, -background => 'white', +-textvariable => \$sernums[5], -validate => 'focusout', -validatecomm +and => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack(); my $partnumSlot5 = $slot5->Entry(-width => 22, -background => 'white', + -textvariable => \$partnums[5], -validate => 'focusout', -validateco +mmand => \&validatePartNum, -invalidcommand => \&invalidPartNum)->pac +k(); my $statusSlot5 = $slot5->Label(-text => '5dormant', -background => 'w +hite', -width => 19, -relief => 'groove', -borderwidth => 3)->pack(-a +nchor => 'center'); my $goSlot5 = $slot5->Button(-width => 10, -height => 1, -text => 'Sta +rt', -background => 'gray', -command => \&compute)->pack(-side => 'to +p', -anchor => 'center'); #################### End Slot 05 #################### #################### Slot 06 #################### my $slot6 = $row2->Frame(-background => 'cyan',)->pack(-side => 'left' +, -pady => 2, -padx => 15); my $descSlot6 = $slot6->Label(-text => 'Slot 06', -background => 'cyan +')->pack(); my $sernumSlot6 = $slot6->Entry(-width => 22, -background => 'white', +-textvariable => \$sernums[6], -validate => 'focusout', -validatecomm +and => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack(); my $partnumSlot6 = $slot6->Entry(-width => 22, -background => 'white', + -textvariable => \$partnums[6], -validate => 'focusout', -validateco +mmand => \&validatePartNum, -invalidcommand => \&invalidPartNum)->pac +k(); my $statusSlot6 = $slot6->Label(-text => '6dormant', -background => 'w +hite', -width => 19, -relief => 'groove', -borderwidth => 3)->pack(-a +nchor => 'center'); my $goSlot6 = $slot6->Button(-width => 10, -height => 1, -text => 'Sta +rt', -background => 'gray', -command => \&compute)->pack(-side => 'to +p', -anchor => 'center'); #################### End Slot 06 #################### #################### Slot 07 #################### my $slot7 = $row2->Frame(-background => 'cyan',)->pack(-side => 'left' +, -pady => 2, -padx => 15); my $descSlot7 = $slot7->Label(-text => 'Slot 07', -background => 'cyan +')->pack(); my $sernumSlot7 = $slot7->Entry(-width => 22, -background => 'white', +-textvariable => \$sernums[7], -validate => 'focusout', -validatecomm +and => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack(); my $partnumSlot7 = $slot7->Entry(-width => 22, -background => 'white', + -textvariable => \$partnums[7], -validate => 'focusout', -validateco +mmand => \&validatePartNum, -invalidcommand => \&invalidPartNum)->pac +k(); my $statusSlot7 = $slot7->Label(-text => '7dormant', -background => 'w +hite', -width => 19, -relief => 'groove', -borderwidth => 3)->pack(-a +nchor => 'center'); my $goSlot7 = $slot7->Button(-width => 10, -height => 1, -text => 'Sta +rt', -background => 'gray', -command => \&compute)->pack(-side => 'to +p', -anchor => 'center'); #################### End Slot 07 #################### #################### Slot 08 #################### my $slot8 = $row2->Frame(-background => 'cyan',)->pack(-side => 'left' +, -pady => 2, -padx => 15); my $descSlot8 = $slot8->Label(-text => 'Slot 08', -background => 'cyan +')->pack(); my $sernumSlot8 = $slot8->Entry(-width => 22, -background => 'white', +-textvariable => \$sernums[8], -validate => 'focusout', -validatecomm +and => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack(); my $partnumSlot8 = $slot8->Entry(-width => 22, -background => 'white', + -textvariable => \$partnums[8], -validate => 'focusout', -validateco +mmand => \&validatePartNum, -invalidcommand => \&invalidPartNum)->pac +k(); my $statusSlot8 = $slot8->Label(-text => '8dormant', -background => 'w +hite', -width => 19, -relief => 'groove', -borderwidth => 3)->pack(-a +nchor => 'center'); my $goSlot8 = $slot8->Button(-width => 10, -height => 1, -text => 'Sta +rt', -background => 'gray', -command => \&compute)->pack(-side => 'to +p', -anchor => 'center'); #################### End Slot 08 #################### my $line3 = $main->Frame(-borderwidth => 3, -relief => 'groove', -background => 'gray')->pack(-side => 'top'); my $row3info = $line3->Label(-text => "Slots 09 - 12", -width => $widt +h, -height => 0, -foreground => 'black', -background => 'gray')->pack(); #################### Row 3 Frame #################### my $row3 = $main->Frame(-background => 'cyan',)->pack(-side => 'top', +-fill => 'x'); my $descriptionrow3 = $row3->Frame(-background => 'cyan',)->pack(-side + => 'left', -pady => 9, -padx => 8); my $t3 = $descriptionrow3->Label(-text => 'Serial Number ', -backgroun +d => 'cyan',)->pack(); $t3 = $descriptionrow3->Label(-text => 'Part Number', -background => ' +cyan',)->pack(); $t3 = $descriptionrow3->Label(-text => 'Status', -background => 'cyan' +,)->pack(); #################### Row 3 Frame #################### #################### Slot 09 #################### my $slot9 = $row3->Frame(-background => 'cyan',)->pack(-side => 'left' +, -pady => 2, -padx => 15); my $descSlot9 = $slot9->Label(-text => 'Slot 09', -background => 'cyan +')->pack(); my $sernumSlot9 = $slot9->Entry(-width => 22, -background => 'white', +-textvariable => \$sernums[9], -validate => 'focusout', -validatecomm +and => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack(); my $partnumSlot9 = $slot9->Entry(-width => 22, -background => 'white', + -textvariable => \$partnums[9], -validate => 'focusout', -validateco +mmand => \&validatePartNum, -invalidcommand => \&invalidPartNum)->pac +k(); my $statusSlot9 = $slot9->Label(-text => '9dormant', -background => 'w +hite', -width => 19, -relief => 'groove', -borderwidth => 3)->pack(-a +nchor => 'center'); my $goSlot9 = $slot9->Button(-width => 10, -height => 1, -text => 'Sta +rt', -background => 'gray', -command => \&compute)->pack(-side => 'to +p', -anchor => 'center'); #################### End Slot 09 #################### #################### Slot 10 #################### my $slot10 = $row3->Frame(-background => 'cyan',)->pack(-side => 'left +', -pady => 2, -padx => 15); my $descSlot10 = $slot10->Label(-text => 'Slot 10', -background => 'cy +an')->pack(); my $sernumSlot10 = $slot10->Entry(-width => 22, -background => 'white' +, -textvariable => \$sernums[10], -validate => 'focusout', -validatec +ommand => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack +(); my $partnumSlot10 = $slot10->Entry(-width => 22, -background => 'white +', -textvariable => \$partnums[10], -validate => 'focusout', -validat +ecommand => \&validatePartNum, -invalidcommand => \&invalidPartNum)-> +pack(); my $statusSlot10 = $slot10->Label(-text => '10dormant', -background => + 'white', -width => 19, -relief => 'groove', -borderwidth => 3)->pack +(-anchor => 'center'); my $goSlot10 = $slot10->Button(-width => 10, -height => 1, -text => 'S +tart', -background => 'gray', -command => \&compute)->pack(-side => ' +top', -anchor => 'center'); #################### End Slot 10 #################### #################### Slot 11 #################### my $slot11 = $row3->Frame(-background => 'cyan',)->pack(-side => 'left +', -pady => 2, -padx => 15); my $descSlot11 = $slot11->Label(-text => 'Slot 11', -background => 'cy +an')->pack(); my $sernumSlot11 = $slot11->Entry(-width => 22, -background => 'white' +, -textvariable => \$sernums[11], -validate => 'focusout', -validatec +ommand => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack +(); my $partnumSlot11 = $slot11->Entry(-width => 22, -background => 'white +', -textvariable => \$partnums[11], -validate => 'focusout', -validat +ecommand => \&validatePartNum, -invalidcommand => \&invalidPartNum)-> +pack(); my $statusSlot11 = $slot11->Label(-text => '11dormant', -background => + 'white', -width => 19, -relief => 'groove', -borderwidth => 3)->pack +(-anchor => 'center'); my $goSlot11 = $slot11->Button(-width => 10, -height => 1, -text => 'S +tart', -background => 'gray', -command => \&compute)->pack(-side => ' +top', -anchor => 'center'); #################### End Slot 11 #################### #################### Slot 12 #################### my $slot12 = $row3->Frame(-background => 'cyan',)->pack(-side => 'left +', -pady => 2, -padx => 15); my $descSlot12 = $slot12->Label(-text => 'Slot 12', -background => 'cy +an')->pack(); my $sernumSlot12 = $slot12->Entry(-width => 22, -background => 'white' +, -textvariable => \$sernums[12], -validate => 'focusout', -validatec +ommand => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack +(); my $partnumSlot12 = $slot12->Entry(-width => 22, -background => 'white +', -textvariable => \$partnums[12], -validate => 'focusout', -validat +ecommand => \&validatePartNum, -invalidcommand => \&invalidPartNum)-> +pack(); my $statusSlot12 = $slot12->Label(-text => '12dormant', -background => + 'white', -width => 19, -relief => 'groove', -borderwidth => 3)->pack +(-anchor => 'center'); my $goSlot12 = $slot12->Button(-width => 10, -height => 1, -text => 'S +tart', -background => 'gray', -command => \&compute)->pack(-side => ' +top', -anchor => 'center'); #################### End Slot 12 #################### my $line4 = $main->Frame(-borderwidth => 3, -relief => 'groove', -background => 'gray')->pack(-side => 'top'); my $row4info = $line4->Label(-text => "Slots 13 - 16", -width => $widt +h, -height => 0, -foreground => 'black', -background => 'gray')->pack(); #################### Row 4 Frame #################### my $row4 = $main->Frame(-background => 'cyan',)->pack(-side => 'top', +-fill => 'x'); my $descriptionrow4 = $row4->Frame(-background => 'cyan',)->pack(-side + => 'left', -pady => 9, -padx => 8); my $t4 = $descriptionrow4->Label(-text => 'Serial Number ', -backgroun +d => 'cyan',)->pack(); $t4 = $descriptionrow4->Label(-text => 'Part Number', -background => ' +cyan',)->pack(); $t4 = $descriptionrow4->Label(-text => 'Status', -background => 'cyan' +,)->pack(); #################### Row 4 Frame #################### #################### Slot 13 #################### my $slot13 = $row4->Frame(-background => 'cyan',)->pack(-side => 'left +', -pady => 2, -padx => 15); my $descSlot13 = $slot13->Label(-text => 'Slot 13', -background => 'cy +an')->pack(); my $sernumSlot13 = $slot13->Entry(-width => 22, -background => 'white' +, -textvariable => \$sernums[13], -validate => 'focusout', -validatec +ommand => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack +(); my $partnumSlot13 = $slot13->Entry(-width => 22, -background => 'white +', -textvariable => \$partnums[13], -validate => 'focusout', -validat +ecommand => \&validatePartNum, -invalidcommand => \&invalidPartNum)-> +pack(); my $statusSlot13 = $slot13->Label(-text => '13dormant', -background => + 'white', -width => 19, -relief => 'groove', -borderwidth => 3)->pack +(-anchor => 'center'); my $goSlot13 = $slot13->Button(-width => 10, -height => 1, -text => 'S +tart', -background => 'gray', -command => \&compute)->pack(-side => ' +top', -anchor => 'center'); #################### End Slot 13 #################### #################### Slot 14 #################### my $slot14 = $row4->Frame(-background => 'cyan',)->pack(-side => 'left +', -pady => 2, -padx => 15); my $descSlot14 = $slot14->Label(-text => 'Slot 14', -background => 'cy +an')->pack(); my $sernumSlot14 = $slot14->Entry(-width => 22, -background => 'white' +, -textvariable => \$sernums[14], -validate => 'focusout', -validatec +ommand => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack +(); my $partnumSlot14 = $slot14->Entry(-width => 22, -background => 'white +', -textvariable => \$partnums[14], -validate => 'focusout', -validat +ecommand => \&validatePartNum, -invalidcommand => \&invalidPartNum)-> +pack(); my $statusSlot14 = $slot14->Label(-text => '14dormant', -background => + 'white', -width => 19, -relief => 'groove', -borderwidth => 3)->pack +(-anchor => 'center'); my $goSlot14 = $slot14->Button(-width => 10, -height => 1, -text => 'S +tart', -background => 'gray', -command => \&compute)->pack(-side => ' +top', -anchor => 'center'); #################### End Slot 14 #################### #################### Slot 15 #################### my $slot15 = $row4->Frame(-background => 'cyan',)->pack(-side => 'left +', -pady => 2, -padx => 15); my $descSlot15 = $slot15->Label(-text => 'Slot 15', -background => 'cy +an')->pack(); my $sernumSlot15 = $slot15->Entry(-width => 22, -background => 'white' +, -textvariable => \$sernums[15], -validate => 'focusout', -validatec +ommand => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack +(); my $partnumSlot15 = $slot15->Entry(-width => 22, -background => 'white +', -textvariable => \$partnums[15], -validate => 'focusout', -validat +ecommand => \&validatePartNum, -invalidcommand => \&invalidPartNum)-> +pack(); my $statusSlot15 = $slot15->Label(-text => '15dormant', -background => + 'white', -width => 19, -relief => 'groove', -borderwidth => 3)->pack +(-anchor => 'center'); my $goSlot15 = $slot15->Button(-width => 10, -height => 1, -text => 'S +tart', -background => 'gray', -command => \&compute)->pack(-side => ' +top', -anchor => 'center'); #################### End Slot 15 #################### #################### Slot 16 #################### my $slot16 = $row4->Frame(-background => 'cyan',)->pack(-side => 'left +', -pady => 2, -padx => 15); my $descSlot16 = $slot16->Label(-text => 'Slot 16', -background => 'cy +an')->pack(); my $sernumSlot16 = $slot16->Entry(-width => 22, -background => 'white' +, -textvariable => \$sernums[16], -validate => 'focusout', -validatec +ommand => \&validateSerNum, -invalidcommand => \&invalidSerNum)->pack +(); my $partnumSlot16 = $slot16->Entry(-width => 22, -background => 'white +', -textvariable => \$partnums[16], -validate => 'focusout', -validat +ecommand => \&validatePartNum, -invalidcommand => \&invalidPartNum)-> +pack(); my $statusSlot16 = $slot16->Label(-text => '16dormant', -background => + 'white', -width => 19, -relief => 'groove', -borderwidth => 3)->pack +(-anchor => 'center'); my $goSlot16 = $slot16->Button(-width => 10, -height => 1, -text => 'S +tart', -background => 'gray', -command => \&compute)->pack(-side => ' +top', -anchor => 'center'); #################### End Slot 16 #################### $main->geometry('+400+200'); # '+10+340' &compute(); $status->configure(-text => "Status Display"); $statusSlot1->configure(-text => "Inactive", -background => 'gray'); $statusSlot2->configure(-text => "Inactive", -background => 'gray'); $statusSlot3->configure(-text => "Inactive", -background => 'gray'); $statusSlot4->configure(-text => "Inactive", -background => 'gray'); $statusSlot5->configure(-text => "Inactive", -background => 'gray'); $statusSlot6->configure(-text => "Inactive", -background => 'gray'); $statusSlot7->configure(-text => "Inactive", -background => 'gray'); $statusSlot8->configure(-text => "Inactive", -background => 'gray'); $statusSlot9->configure(-text => "Inactive", -background => 'gray'); $statusSlot10->configure(-text => "Inactive", -background => 'gray'); $statusSlot11->configure(-text => "Inactive", -background => 'gray'); $statusSlot12->configure(-text => "Inactive", -background => 'gray'); $statusSlot13->configure(-text => "Inactive", -background => 'gray'); $statusSlot14->configure(-text => "Inactive", -background => 'gray'); $statusSlot15->configure(-text => "Inactive", -background => 'gray'); $statusSlot16->configure(-text => "Inactive", -background => 'gray'); MainLoop(); sub compute { return; } sub validateSerNum { my $sernum = shift; print "validateSerNum called with $sernum\n"; if (($sernum =~ m/^\d{8}/) && (length($sernum) == 8)) { print "Returning 1\n"; return(1); } else { print "Returning 0\n"; return(0); } } sub invalidSerNum { $main->bell; $main->messageBox(-icon => 'error', -message => 'Serial number mus +t be 8 digits!', -title => 'Error', -type => 'Ok'); $main->focusCurrent; } sub validatePartNum { my $partnum = shift; print "validatePartNum called with $partnum\n"; if (($partnum =~ m/^\d{8}/) && (length($partnum) == 8)) { print "Returning 1\n"; return(1); } else { print "Returning 0\n"; return(0); } } sub invalidPartNum { $main->bell; $main->messageBox(-icon => 'error', -message => 'Invalid part numb +er!', -title => 'Error', -type => 'Ok'); $main->focusCurrent; }

Replies are listed 'Best First'.
Re: Help with TK writing shorter code
by jdporter (Paladin) on Sep 10, 2011 at 02:54 UTC

    Yes. You need to take advantage of subroutines and arrays. Below is my refactoring of your code to use arrays to hold all the slot info, and subroutines to build the similar screen components. Compare it carefully with what you have. Note - I have not attempted to do anything with your validation subroutines and other stuff.

    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
      Thanks for your help. Is there a way to identify which slot a given start button is associated with? Thanks.
        The button is defined by $x, in the sub make_slot
        $goSlot[$x] = $slot->Button()
        so keep track of $x.

        What are you trying to do with the button tracking?


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh