Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > HTML::Template->param() : You gave me an odd number of parameters to param()!

Reply
Thread Tools

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

 
 
Dave
Guest
Posts: n/a
 
      04-25-2011
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
 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      04-25-2011
Dave wrote:
> 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.
 
Reply With Quote
 
 
 
 
sln@netherlands.com
Guest
Posts: n/a
 
      04-25-2011
On Mon, 25 Apr 2011 13:46:24 -0700 (PDT), Dave <> wrote:

>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
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      04-25-2011
writes:

> On Mon, 25 Apr 2011 13:46:24 -0700 (PDT), Dave <> wrote:


>>$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.

--
John Bokma j3b

Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma
Freelance Perl & Python Development: http://castleamber.com/
 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      04-26-2011
On Mon, 25 Apr 2011 18:37:38 -0500, John Bokma <> wrote:

> writes:
>
>> On Mon, 25 Apr 2011 13:46:24 -0700 (PDT), Dave <> wrote:

>
>>>$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
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      04-26-2011
Tad McClellan <> writes:

> John Bokma <> wrote:
>> writes:
>>
>>> On Mon, 25 Apr 2011 13:46:24 -0700 (PDT), Dave <> wrote:

>>
>>>>$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

--
John Bokma j3b

Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma
Freelance Perl & Python Development: http://castleamber.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why I gave up on Firefox History Fan Firefox 45 09-15-2005 10:51 PM
Gave away 10 CDs damon Firefox 0 11-04-2004 02:11 PM
you gave me a grin and a chuckle Scott D MCSE 3 10-28-2003 03:11 PM
Re: 70-220 Gave Score Japes MCSE 1 08-20-2003 09:37 AM
70-220 Gave Score ITPro_DLM MCSE 0 08-14-2003 01:59 AM



Advertisments