in reply to Hash of Arrays using Perl::Tk
There still is room for improvement ;-)use strict; use warnings; use Tk; use Tie::IxHash; my %hash; my @w; my $i=1; tie %hash, "Tie::IxHash"; %hash =( 1=>["Sappy", "Jewell", "2515 E Princeton", "Visalia", "CA" ], 2=>["Roomy", "Hilton", "12803 Westledge Ln", "Fifa", "Transvania"], 3=>[ "Lala", "Deena", "423 Northland Street", "St. Louis", "Misery" ], 4=>[ "LOLO", "Homy", "444 Wold City", "Foxy", "Flowerida" ], ); my @fields = qw/First_Name Last_Name Address City State /; my $mw=MainWindow->new (-title=>"Data Test"); my $rec_no=keys %hash; my $label = $mw->Label(-text=>"dummy_label"); $label->pack; my $t=$mw->Scrolled("Text",-width=>50,-wrap=>'none')->pack(-expand=>1, +-fill=>'both'); for my $index (0..4) { $w[$index]=$t->Label(-text=>"$fields[$index]",-relief=>'groove',-w +idth=>20); $t->windowCreate('end',-window=>$w[$index]); $w[$index]=$t->Entry(-width=>20,-textvariable=>\$hash{$i}[$index]) +; $t->windowCreate('end',-window=>$w[$index]); $t->insert('end',"\n"); } my $next =$mw->Button ( -relief=>'raised', -text=>"Next >>", -state=>' +normal',-command=>\&next ); my $back =$mw->Button(-relief=>'raised', -text=>"<< Back", -state=>'no +rmal',-command=>\&back ); &process_rows(); MainLoop; sub process_rows{ $next->configure(-text=>"Next", -state=>'normal',-command=>\&next) +; $back->configure(-text=>"Back", -state=>'normal',-command=>\&back) +; $back->configure(-text=>"Back", -state=>'disabled',-command=>\&bac +k) if $i == 1; $next->configure(-text=>"Next", -state=>'disabled',-command=>\&nex +t) if $i == $rec_no; for my $k(0..4){ $label->configure(-text=>"$i"); $label->pack; $w[$k]->configure(-textvariable=>\$hash{$i}[$k]); $t->configure(); $back->pack(-anchor=>'center', -side=>'left'); $next->pack(-anchor=>'center', -side=>'right'); } } sub next{ $i++ unless $i == $rec_no; &process_rows(); } sub back{ --$i unless $i == 1; &process_rows(); }
|
|---|