HTML::Template->param() : You gave me an odd number of parameters to param()!

D

Dave

Hi,

I'm using Perl 5.10.1. I'm trying to fill in an HTML::Template, which
consists of

<TMPL_LOOP NAME=TESTS>
<tr><td><a href="<TMPL_VAR NAME=ABSOLUTE_PATH>"><TMPL_VAR
NAME=FILE_SHORT_NAME></a></td></tr>
</TMPL_LOOP>


but I'm getting an error when I try and do the following ...

my @loop_arr;
foreach (@test_files) {
my $test_file = $_;
my %params_hash;
$params_hash{'absolute_path'} = $test_file;
$params_hash{'file_short_name'} = $test_file;
push(@loop_arr, %params_hash);
}
# open the html template
my $template = HTML::Template->new(filename => '/opt/scripts/selenium/
report_suite.templ');
$template->param(TESTS => @loop_arr);

The error is complaining about the last line. I tried changing
"@loop_arr" to "$loop_arr" but that gave some undefined variable
errors. Could someone point out the error(s) of my ways?

Thanks, - Dave
 
J

J. Gleixner

Dave said:
Hi,

I'm using Perl 5.10.1. I'm trying to fill in an HTML::Template, which
consists of

<TMPL_LOOP NAME=TESTS>
<tr><td><a href="<TMPL_VAR NAME=ABSOLUTE_PATH>"><TMPL_VAR
NAME=FILE_SHORT_NAME></a></td></tr>
</TMPL_LOOP>


but I'm getting an error when I try and do the following ...

my @loop_arr;
foreach (@test_files) {
my $test_file = $_;
my %params_hash;
$params_hash{'absolute_path'} = $test_file;
$params_hash{'file_short_name'} = $test_file;
push(@loop_arr, %params_hash);
push( @loop_arr, \%params_hash );
}
# open the html template
my $template = HTML::Template->new(filename => '/opt/scripts/selenium/
report_suite.templ');
$template->param(TESTS => @loop_arr);

$template->process(TESTS => \@loop_arr);
The error is complaining about the last line. I tried changing
"@loop_arr" to "$loop_arr" but that gave some undefined variable
errors. Could someone point out the error(s) of my ways?

Give the documentation a try.
 
S

sln

Hi,

I'm using Perl 5.10.1. I'm trying to fill in an HTML::Template, which
consists of

<TMPL_LOOP NAME=TESTS>
<tr><td><a href="<TMPL_VAR NAME=ABSOLUTE_PATH>"><TMPL_VAR
NAME=FILE_SHORT_NAME></a></td></tr>
</TMPL_LOOP>


but I'm getting an error when I try and do the following ...

my @loop_arr;
foreach (@test_files) {
my $test_file = $_;
my %params_hash;
$params_hash{'absolute_path'} = $test_file;
$params_hash{'file_short_name'} = $test_file;
push(@loop_arr, %params_hash);
}
# open the html template
my $template = HTML::Template->new(filename => '/opt/scripts/selenium/
report_suite.templ');
$template->param(TESTS => @loop_arr);
maybe => [@loop_arr]

since => imply's a hash element, which can't be an array,
but can be a reference to an array.

-sln
 
J

John Bokma

$template->param(TESTS => @loop_arr);
maybe => [@loop_arr]

since => imply's a hash element, which can't be an array,
but can be a reference to an array.

In which case you might want to use => \@loop_arr instead. Correct me if
I am wrong but you're now copying @loop_arr into an empty hash you
created a reference too. Sometimes that's what you want (for example if
you want to keep a copy), but in this case most likely not.
 
S

sln

$template->param(TESTS => @loop_arr);
maybe => [@loop_arr]

since => imply's a hash element, which can't be an array,
but can be a reference to an array.

In which case you might want to use => \@loop_arr instead. Correct me if
I am wrong but you're now copying @loop_arr into an empty hash you
created a reference too. Sometimes that's what you want (for example if
you want to keep a copy), but in this case most likely not.

It was hard to tell what he wanted to do. Looked like he wanted to copy
the array to this place, therefore the new array. Otherwise, it appears
if he doesen't know what [] is, he isin't going to know what \@ar is.
I stopped guessing what's in the minds of people.

-sln
 
J

John Bokma

Tad McClellan said:
John Bokma said:
$template->param(TESTS => @loop_arr);

maybe => [@loop_arr]

since => imply's a hash element, which can't be an array,
but can be a reference to an array.

In which case you might want to use => \@loop_arr instead. Correct me if
I am wrong but you're now copying @loop_arr into an empty hash you
^^^^
^^^^
s/hash/array/;

Thanks Tad, indeed that should have read array :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top