i'm not a
perl monk . . . but this works:
Code:
#!/usr/bin/perl
#----------------------------------------------------------------------#
# Read both files into arrays... #
#----------------------------------------------------------------------#
$param_file = "parameters.dat";
unless ( open FIN, "$param_file" ){
print "cannot open $param_file \n";
exit(1);
}
@a_parameters = <FIN>; chomp @a_parameters; close FIN;
$template_file = "template.dat";
unless ( open FIN, "$template_file" ){
print "cannot open $template_file \n";
exit(1);
}
@a_template = <FIN>; chomp @a_template; close FIN;
#----------------------------------------------------------------------#
# Peruse one array... #
#----------------------------------------------------------------------#
for $x ( 0 .. scalar( @a_parameters ) - 1 ){
( $var_name, $equals, $var_value ) = split( / /, $a_parameters[$x] );
$var_name = uc( $var_name );
#----------------------------------------------------------------------#
# Looking for values in the other... #
#----------------------------------------------------------------------#
for $y ( 0 .. scalar( @a_template ) - 1 ){
next unless ( $template[$y] = m/CX_*$var_name = / );
#----------------------------------------------------------------------#
# Substitute the template with the parameter... #
#----------------------------------------------------------------------#
$a_template[$y] =~ s/= .*$/= $var_value/;
}
}
#----------------------------------------------------------------------#
# ... and print. #
#----------------------------------------------------------------------#
for $y ( 0 .. scalar( @a_template ) - 1 ){
print "template entry " . ( $y + 1 ) . ": $a_template[$y] \n";
}