Hi,
I'm quite newbie in perl world. I need to create perl script in unix system to analyse original file and after that replace footer with empty line, and after that execute system command..
So far i have problems replace footer with empty line and writing modifications into new file . Here is my script.
open(RAW, "$file");
while(<RAW>) {
chomp;
$trailer = 0;
$line = $_."\n";
if ($line =~ m/TRAILER/){
$trailer = 1;
}
}
unless ($trailer == 1){
$error = "Error message. \n";
&error_msg($error);
die $error;
}
close (RAW);
&write_status("making copy of raw mnp file\n");
system("cp $file $tmp_file");
//this doesn't work
sub write_mnp_trailer {
$line=$_;
open (IN, "< $tmp_file");
open (OUT, ">$mnp_file");
while(<IN>){
chomp;
if($rida =~ m/TRAILER/){
$rida =~ s/TRAILER//;
$trailer = 1;
}
print (OUT "$_\n");
}
close IN;
close OUT;
}
die;
&write_status("checking file\n");
$state = 0;
$i = 0;
&write_status("Starting uploading mnp tables )\n");
while ($state != 1){
if($i > 4){
$error = "Script tried more than 5 times
(\n";
&error_msg($error);
die $error;
}
system(". load_param $mnp_file"." 1>program.stdout 2>program.stderr");
open(OUT, "program.stdout");
while(<OUT>) {
chomp;
$line = $_;
if ($line =~ m/OK/){
$state = 1;
}
}
close (OUT);
$i++;
}
&write_status("finished, files writed into archive\n");
system("mv $mnp_file $file_arch");
...
I
I'm quite newbie in perl world. I need to create perl script in unix system to analyse original file and after that replace footer with empty line, and after that execute system command..
So far i have problems replace footer with empty line and writing modifications into new file . Here is my script.
open(RAW, "$file");
while(<RAW>) {
chomp;
$trailer = 0;
$line = $_."\n";
if ($line =~ m/TRAILER/){
$trailer = 1;
}
}
unless ($trailer == 1){
$error = "Error message. \n";
&error_msg($error);
die $error;
}
close (RAW);
&write_status("making copy of raw mnp file\n");
system("cp $file $tmp_file");
//this doesn't work
sub write_mnp_trailer {
$line=$_;
open (IN, "< $tmp_file");
open (OUT, ">$mnp_file");
while(<IN>){
chomp;
if($rida =~ m/TRAILER/){
$rida =~ s/TRAILER//;
$trailer = 1;
}
print (OUT "$_\n");
}
close IN;
close OUT;
}
die;
&write_status("checking file\n");
$state = 0;
$i = 0;
&write_status("Starting uploading mnp tables )\n");
while ($state != 1){
if($i > 4){
$error = "Script tried more than 5 times
&error_msg($error);
die $error;
}
system(". load_param $mnp_file"." 1>program.stdout 2>program.stderr");
open(OUT, "program.stdout");
while(<OUT>) {
chomp;
$line = $_;
if ($line =~ m/OK/){
$state = 1;
}
}
close (OUT);
$i++;
}
&write_status("finished, files writed into archive\n");
system("mv $mnp_file $file_arch");
...
I