#!/usr/bin/perl
# preprocess - replace fields in an input file with values from variables.list
# Copyright (C) 2008 Hewlett-Packard Development Company, L.P.

use Text::Template;

$list=$ARGV[0];
$form=$ARGV[1];

open LIST,$list or die "Can't open $list\n";

# load the file into a hash
while (<LIST>) {
   m/^(\w*?)="(.*)"$/;
   $vars{"$1"}="$2";
}

my $template = Text::Template->new(SOURCE => "$form")
   or die "Couldn't construct template: $Text::Template::ERROR";

my $result = $template->fill_in(HASH => \%vars);

if (defined $result) { print $result } else { die "Couldn't fill in template: $Text::Template::ERROR" };
