#!/opt/usr/bin/perl5.005 -w use Tk 800; use diagnostics; # Open up the file and input information and data points. # Sort variables by i_ for information and d_ for data. sub open_file { open RF, "/opt/adacs/perl_learn/read_file" or die "Can't open read_file"; } &open_file; my @info = (grep /i_/, ); close RF; &open_file; my @data = (grep /d_/, ); close RF; #After sorting, remove i_ and d_ identifiers. for (@info) { s/i_//; } for (@data) { s/d_//; } #split each word in @data into individual elements in an array reference. for (@data) { push(@{$arrays}, [split(/ /)]); } # Create window. Show Info and data information. # Give user the opportunity to overwrite saved values. # Ask if user wants to restore data or cancel. # Main Window with set size. my $mw = MainWindow->new(); $mw->geometry("400x650"); # First frame holds the information that was imported from file. $frame1 = $mw->Frame(-borderwidth => 2, -relief => 'groove')->pack(-fill => 'x'); $frame1->Label(-text => "Data saved at:")-> pack(-side => 'top', -expand => 1, -pady => '25'); for (@info) { $frame1->Label(-text => $_, -justify => 'left', -width => 30, -anchor => 'w')-> pack(); } # The second frame just holds a title and some column headers. $frame2 = $mw->Frame(-width => 400, -borderwidth => 2)->pack(); $frame2->Label(-text => "Data to Restore:")-> pack(); $frame2->Label(-text => "Point Saved Current", -anchor => 'w', -width => 30)-> pack(); # The third frame holds the point names which are from column 1 of the imported file. $frame3 = $mw->Frame(-width => 5, -height => 10, -borderwidth => 2)->pack(-side => 'left', -ipadx => 10, -fill => 'y'); my $i = 0; for (@{$arrays}) { $frame3->Label(-text => $arrays->[$i][0], -borderwidth => 5)-> pack(-side => 'top', -fill => 'x', -ipady => 6); $i++; } # When the user clicks this button the data will be restored. $frame3->Button(-text => "Restore", -command => \&restore_data)-> pack(-side => 'top', -padx => '15', -pady => '40'); # The fourth frame holds the point values that were saved before the power shutdown. $frame4 = $mw->Frame(-width => 10, -borderwidth => 2)-> pack(-side => 'left', -ipadx => 10, -fill => 'y'); $i = 0; for (@{$arrays}) { $frame4->Entry(-textvariable => \$arrays->[$i][1], -width => 6)-> pack(-fill => 'x', -ipady => 9); $i++; } # The fifth frame holds the current point values. $frame5 = $mw->Frame(-borderwidth => 2,)->pack(-side => 'left', -ipadx => 10, -fill => 'y'); $i = 0; for (@{$arrays}) { $frame5->Label(-text => $arrays->[$i][2], -anchor => 'center')-> pack(-fill => 'x'); $i++; } $frame5->Button(-text => "Cancel", - command => sub { exit})-> pack(-side => 'right', -padx => '15', -pady => '15'); $mw->title("Data Restore"); MainLoop; # Restore values sub restore_data { my $m = 0; for (@{$arrays}) { my $key = $arrays->[$m][0]; my $value = $arrays->[$m][1]; my %res_values = ( $key => $value ); system "XXXXX $key $value"; $m++; }; {exit} }