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

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

Post by Dave » Wed, 27 Apr 2011 05:46:24


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
 
 
 

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

Post by J. Gleixne » Wed, 27 Apr 2011 06:21:33


push( @loop_arr, \%params_hash );


$template->process(TESTS => \@loop_arr);

Give the documentation a try.

 
 
 

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

Post by sln » Wed, 27 Apr 2011 06:24:23


maybe => [@loop_arr]

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

-sln
 
 
 

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

Post by John Bokm » Wed, 27 Apr 2011 08:37:38


XXXX@XXXXX.COM writes:




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.

--
John Bokma j3b

Blog: http://www.yqcomputer.com/ : http://www.yqcomputer.com/
*** Perl & Python Development: http://www.yqcomputer.com/
 
 
 

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

Post by sln » Wed, 27 Apr 2011 10:01:42


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
 
 
 

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

Post by Tad McClel » Wed, 27 Apr 2011 10:16:41


^^^^
^^^^
s/hash/array/;




--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
 
 
 

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

Post by John Bokm » Wed, 27 Apr 2011 11:44:15

Tad McClellan < XXXX@XXXXX.COM > writes:




Thanks Tad, indeed that should have read array :-)

--
John Bokma j3b

Blog: http://www.yqcomputer.com/ : http://www.yqcomputer.com/
*** Perl & Python Development: http://www.yqcomputer.com/