r.joseph has asked for the wisdom of the Perl Monks concerning the following question:

Happy Holidays fellow monks!!

Well, I gave in and installed Template Toolkit, and I am very happy to say that I am loving it - it is a good as everyone said it was.

Here is my question. In constructing the 'vars' array that holds all the varibles that will be processed, I want to do this:
%vars = { name => value, n => v, ...}; $template->process($file,\%vars);
thus, passing a hash reference to the process() function, which is exactly what it calls for. Yet, whenever I do this, it doesn't work, but the next code DOES:
$vars = { name => value, n => v, ...}; $template->process($file, $vars);

Now, how come the latter works, when the former doesn't?? Aren't they both exactly the same thing? The reason I want to use the former is because I want to be able to update the varibles in the vars array on the fly, ie $vars{'name'} = new_value.

Thanks so much to everyone, you guys are a very great help!! And I am sure there is more questions to come, so brace for impact :-).

R.Joseph

Replies are listed 'Best First'.
Re: Teplate Toolkit Question
by extremely (Priest) on Dec 29, 2000 at 14:29 UTC
    I think you mean:
    $vars = { }; #squiggly braces # or %vars = ( ); #parens

    I'm pretty sure that you can't use a reference as a hash key effectively in this situation.

    --
    $you = new YOU;
    honk() if $you->love(perl)

Re: Template Toolkit Question
by davorg (Chancellor) on Dec 29, 2000 at 15:03 UTC

    extremely has gioven you the correct solution to your problem, but I'd just like to point out that had you been using the -w flag in your code then perl would have pointed out your error to you. For example, running Perl 5.005_03, I get the following:

    $ perl -w -e 'my %hash = { one => 1}' Reference found where even-sized list expected at -e line 1. $
    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

Re: Teplate Toolkit Question
by $code or die (Deacon) on Dec 29, 2000 at 16:20 UTC
    You already have some good answers to this question, but you can still update the $vars hash on the fly by doing this:
    $vars->{'name'} = new_value;