[Pdx-pm] Re: Pass by reference(?)

Greg Minter gminter at hevanet.com
Tue Mar 23 23:56:49 CST 2004

  Roderick A. Anderson wrote:

>I'm using HTML:Template to fill in some HTML (go figure) and XML 
>templates.  I use a hash to hold the template variables and then use this 
>    my $add_plans = HTML::Template->new(
>            filename => "$TemplateDIR/$Template",
>            die_on_bad_params => 0);
>    foreach my $key (keys %SUI) {
>        $add_plans->param($key => $SUI{$key});
>    }
>And though it's only 2 lines of code it goes (to my way of thought) 
>against the grain.  I'd like to do something like a fill_form subroutine 
>that I could call.  The hash (%SUI) is global (main) but $add_plans is 
>local to the subroutine it is in.
  The param() method will also accept a hash reference, so you don't 
need to use a loop. The lines:

    foreach my $key (keys %SUI) {
        $add_plans->param($key => $SUI{$key});

   can be replaced by :

         $add_plans->param(  \%SUI);

    This is described in the HTML::Template page.

   By the way, if your only task is filling in values on form fields, 
 then check out the CPAN
module HTML::FillInForm. It does all the work of filling in values for 
all types of input fields,
even radio buttons and selections.

   I hope this helps,

More information about the Pdx-pm-list mailing list