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


in reply to Re: Importing a variable into a package (updated)
in thread Importing a variable into a package

Thanks for the detail explanation !

From my tests with Text::Template, I saw that I had to name variables without the package component to catch syntax errors. Having read the docs (sorry, can't find exactly where) this became clearer.

There is no begin bloc in the loop that gives values to the glob variables Re: Text::Template and delayed use vars as in your last working example

eval ' package T; print "B: $x\n"; 1 ' or warn "B: $@";

This seems to be what happen in the module (version 1.47), around line 309 (the print line is mine):

sub fill_in { ... my $fi_progtext = "package $fi_eval_package; $fi_prepend;\n$fi_lcomment\n$fi_tex +t;"; ... print "eval on \n", $fi_progtext,"\n"; $fi_res = eval $fi_progtext;

Which prints

eval on package T; use strict;; #line 1 dokpe.tmpl $annee ; eval on package T; use strict;; #line 4 dokpe.tmpl "\t";
For a template file starting with
Plan de fermeture { $annee } Bibliothèque de la Faculté des Sciences (Dokpe) Motif{"\t"}

So to be sure I understand correctly: since I use eval during the script runtime, I do not need the begin block to assign a value to the glob. In my example above, the begin was needed because the print statement was run during the execution time. Is that correct ?

Thanks again

François