#!/usr/local/bin/perl -pi.OLD

# Use this script to change the value field of a certify template file
# The file names are taken from the command line and the files are 
# modified in place. The original file is saved with the extension .OLD

# Configuration variables: the names of the lines to change 
# and the value to set them to

@name = ('FILE_NAME', 'COMPARISON_FILE');
$new_value = '&FILENAME';

if (/^\#.+VALUES/) {
    $col = index ($_, "VALUES");

} elsif (! /^\#/) {
    # Expand tabs
    while (s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {
    }
	    
    # Split into fields, retaining whitespace
    @field = split (/(\s+)/, $_);

    for $name (@name) {
	if ($name eq $field[0]) {
	     # Drop current values field
	    $_ = join ('', @field[0..6]);
	    
	     # Add proper spacing and new values field
	    $len = length ($_);
	    $_ .= ' ' x ($col - $len) . "$new_value\n";

	    last;
	}
    }
}
