Feral_Shade has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am using the HTML::Template->param() function to fill out some online forms that I have, and I have the following problem:

you have to assign the values like this:

param(varname => "value");
and I need to be able to use a variable in place of the hash key. Something like the following
$template = HTML::Template->new(filename => "file.tmpl"); $varname = "var1"; $template->param($varname => "value");

I know that the above code is invalid.... Is there some way to do this? Thanks.

Replies are listed 'Best First'.
Re: Variable Hash assignments
by jonnyfolk (Vicar) on Apr 20, 2003 at 20:33 UTC
    Using the example script in the HTML:: Template description, I used the following script:
    #!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI ':standard'; my $varname = "path"; use HTML::Template; # open the HTML template my $template = HTML::Template->new(filename => 'test.tmpl'); # fill in some parameters in the template $template->param(home => $ENV{HOME}); $template->param($varname => $ENV{PATH}); # send the obligatory Content-Type print "Content-Type: text/html\n\n"; # print the template print $template->output;
    Which worked no problem. You might like to try it out - it may help you to find the real source of your problem?
Re: Variable Hash assignments
by benn (Vicar) on Apr 20, 2003 at 20:14 UTC
    Looks valid-and-dandy to me...do you get an error/ does it not it work when you do this?
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Variable Hash assignments
by benn (Vicar) on Apr 20, 2003 at 20:40 UTC
    Much as I enjoy having conversations line-by-line, posting some more code / error messages / things-you've-tested etc. might help a little in the analysis of this particular problem. In theory, the code there should work fine - if it's not working, it's probably to do with other stuff around it.
    Cheers
    Ben
      Thanks for all of the replies, I figured out why it wasn't working and I have fixed it (I had a typo in the template file... oops :) )