I am trying to read from two files and generate output in the third. At first I wanted to edit the first one on the go, but I did not find a suitable method for saving arrays.
My problem is that the third file (output) is empty when I uncomment the function "_ref_param_handling". BUT , which puzzles me most: if I make UNIX a very simple `cat` system call in the output file at the end (see code below), it works fine. If I open the file descriptor just before this and close it right after editing, it also works fine (around my FILEHANDLE LIST sheet).
Undoubtedly, I missed something here. Besides the problem between my keyboard and my chair, what is it? File descriptor conflict? Problem with area?
Each variable is declared and has the value that I want to have.
Change (no longer applicable). Using IO :: File in three files did not change anything.
Edit 2: New full routine code
My code works (unless my ref already exists, but because of the "append" mode, which I think), but there may be some errors and incorrect coding methods (sorry, Monks). However, I use Strict and warnings !
sub _ref_edit($) {
my $manda_def = "$dir/manda_def.list";
my $newrefhandle;
my $ref = $_[0];
(my $refout = $ref) =~ s/empty//;
my $refhandle;
my $parname = '';
my $parvalue = '';
my @val;
_printMan;
my $flush = readline STDIN;
if ( !( -e $manda_def && -e $ref ) ) {
die "Cannot find $ref and/or $manda_def";
}
open( $refhandle, "<", $ref ) or die "Cannot open ref $ref : $!";
open( $newrefhandle, ">>", $refout )
or die "Cannot open new ref $refout : $!";
while ( my $refline = <$refhandle> ) {
if ( $refline =~ /^define\({{(.+)}},\s+{{.*__VALUE__.*}}\)/ ){
$parname = $1;
$parvalue = _ref_param_handling( $parname, $manda_def );
$refline =~ s/__VALUE__/$parvalue/;
$parvalue eq '' ? $refline=~s/__COM__/#/ : $refline=~s/__COM__//;
}
print $newrefhandle $refline;
}
close $newrefhandle;
close $refhandle;
return $refout;
}
the _ref_param_handle routine is still:
open( $mde, '<', $_[1] )
or die "Cannot open mandatory/default list $_[1] : $!";
while (<$mde>) {
( $name, $manda, $default, $match, $descript ) = split( /\s+/, $_, 5 );
next if ( $name !~ $ref_param );
(SOME IF/ELSE)
}
close $mde;
return $input;
}
Extract from manda_def file:
NAME Mandatory? Default Match Comm.
PORT y NULL ^\d+$ Database port
PROJECT y NULL \w{1,5} Project name
SERVER y NULL \w+ Server name
modemRouting n NULL .+
modlib y bin .+
modules y sms .+
Extract from file ref_file:
define({{PORT}}, {{__VALUE__}})dnl
define({{PROJECT}}, {{__VALUE__}})dnl
define({{SERVER}}, {{__VALUE__}})dnl
define({{modemRouting}}, {{__COM__{{$0}} '__VALUE__'}})dnl
define({{modlib}}, {{__COM__{{$0}} '__VALUE__'}})dnl
define({{modules}}, {{__COM__{{$0}} '__VALUE__'}})dnl
Any help was appreciated.