#!/usr/bin/perl -w
use strict;

use Text::Template;

my $VARS = {};

while(@ARGV) {
    if ($ARGV[0] =~ m/(.*)=(.*)/) {
	$VARS->{$1} = $2;
	shift @ARGV;
    }
    else {last}
}
die "no vars supplied" unless scalar(keys %$VARS);
die "no file specified" unless @ARGV;
my $file = shift @ARGV;

my $template = $file eq '-' ? Text::Template->new(TYPE => 'FILEHANDLE', SOURCE => \*STDIN) : Text::Template->new(TYPE => 'FILE', SOURCE => $file);
print STDERR "About to fill in substitutions in template file $file\n";
my $text = $template->fill_in(HASH => $VARS);
print $text;
print STDERR "Wrote ", length($text), " characters to output\n";
exit(0);
