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


In reply to Re^2: Importing a variable into a package by frazap
in thread Importing a variable into a package by frazap

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.