#!/usr/bin/perl
# 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 (outfile1, ">$prefile1") || die ("Could not open file.
$!");# Open The File
open (outfile2, ">$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($string =~ /# __START_CONFIG__/i) {
$action=2;
}
if($string =~ /# __END_CONFIG__/i) {
$action=3;
}
if ( $action == 1 ) {
# write to outfile1
print outfile1 "$value";
}
if ($action == 3) {
# write to outfile2
print outfile2 "$value";
}
if ($action == 2) {
# copy string to new array
}
}
close (sample);
close (outfile1);
close (outfile2);