#!/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_/, <RF>); close RF; &open_file; my @data = (grep /d_/, <RF>); 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 referen +ce. 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', -expa +nd => 1, -pady => '25'); for (@info) { $frame1->Label(-text => $_, -justify => 'left', -width => 30, -anc +hor => '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 th +e imported file. $frame3 = $mw->Frame(-width => 5, -height => 10, -borderwidth => 2)->p +ack(-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} }

In reply to Value Restoration by Lhamo_rin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.