Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Value Restoration

by Lhamo_rin (Friar)
on Jun 27, 2003 at 13:13 UTC ( [id://269533]=sourcecode: print w/replies, xml ) Need Help??
Category: Utility Scripts
Author/Contact Info Lhamo_rin
Description: Thanks to the help I received from my fellow monks I was able to finish this script. I use it to restore certain values after a power failure that would, by default, be reset to 0. The user is prompted with the option of restoring the old values, overwriting with new, or canceling altogether. The read_file is just variable names and values separated by whitespace. I though someone might be able to use it.

#!/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}   
    }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://269533]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-18 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found