#!/usr/bin/perl
use HTML::Template
# Open File - Read File Contents Then Modify & save contents
# Specify name of file
$data_file="sample.pm";
# Name of temp file 1
$prefile1="/tmp/123456.beg";
# Name of temp file 2
$prefile2="/tmp/123456.end";
$action = 1;
# Open File abd read it all in to rawdata
open (file_beg, ">$prefile1") || die ("Could not open file.
$!");# Open The File
open (file_end, ">$prefile2") || die ("Could not open file.
$!");# Open The File
open (sample, "$data_file") || die ("Could not open file.
$!");# Open The File
flock(sample, 2) or die "cannot lock file exclusively: $!";# Lock The File
@rawdata = ;# Put data from file into array called sample
# write data from sample.pm into beg_non_edit
foreach $value (@rawdata) {
print ("$value\n");
if($value =~ /# __END_CONFIG__/i) {
$action=3;
}
if ( $action == 1 ) {
# write to file_beg
print file_beg "$value"; # as long as action is 1 it should write to this file.
}
if ($action == 3) {
# write to file_end
print file_end "$value"; # as long as action is 3 it will write to this file
}
if ($action == 2) {
push @allow_edit, $value; # copy string to new array
}
if($value =~ /# __START_CONFIG__/i) {
$action=2;
}
}
close (sample);
close (file_beg);
close (file_end);
$template = HTML::Template->new(filename => 'template/editor.tmpl');
my @loop;
#fill in the array @loop with hash references from @allow_edit...
foreach (@allow_edit){
my($name, $value) = split /=/,$_;
push @loop, {part1=>$name, part2=>$value};
}
# fill in the loop,
foreach my $name (sort keys %loop_data) {
# get the color and shape from the data hash
my ($name, $value) = @{$loop_data};
}
#call param to fill in the loop with the loop data by reference.
$template->param(loop => \@loop);
print "Content-Type: text/html\n\n";
# print the template
print $template->output;