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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|