http://qs321.pair.com?node_id=1214051


in reply to Text::Template and delayed use vars

Yes it's possible, reading Simon Cozens' Advanced Perl, I found this whitch work:
foreach my $f (@files) { my $config = Config::YAML::Tiny->new( config => $f ); my @template_file = split( / /, $config->get_template ); foreach my $tf (@template_file) { my @fields = split( / /, $config->get_fields ); for my $v ( @fields ) { no strict 'refs'; *{"T::$v"}= \$config->{$v}; } my $template = Text::Template->new( TYPE => 'FILE', SOURCE => $tf ) or die "Couldn't construct template: $Text::Template::ERROR" +; my $result = $template->fill_in( PACKAGE => 'T', PREPEND => 'use strict;' ); ...

And in the template file(s) I had to change $value with $T::value, $pos with $T::pos

update In fact, with $T::pos in the template file, I loose the error if the variable name is wrong: $T:ops is just replace by nothing but no error is given. I have to use $pos or $value in the template.

The docs could be made clearer I think

F.