The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 02-10-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
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";
  }

Last edited by quirkasaurus; 02-10-2009 at 02:35 PM.. Reason: clean up...