Attempt #1-3 are missing a comma between your array and your list. Solution, use a comma.
Attempt #4 is assigning an array reference as the first element of an array and then you are using a reference to that array. Solution, use () instead of [] in your assignment. Attempt #5 is a hashref not an array ref. Solution, put all your hash elements into an array. Attempt #6 is a hash itself, not even an array. I'd recommend using #1 with a comma like so (push @test, { name=>"foo",value=>"blitz" };) and you should be working. --Jayson Ken Corey <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] 11/24/03 02:55 PM To: [EMAIL PROTECTED] cc: Subject: [htmltmpl] (newbie) How to populate an array of hash references one by one? Hi All, I'm playing with HTML::Template, and I've run into something that should be easy, but I don't see how it can work. The docs say to pass many elements for a loop, you do this: $template->param( loopvar => [ { name=>"foo",value=>"baloney" }, { name=>"bar",value=>"tiple" }, { name=>"blah",value=>"mulroney" }, ], ); So, I'm using anonymous array and hash operators to make an anonymous array of hash references. (page 246, "The anonymous array composer", camel book). That's great, but what if you don't know your content at programming time? {Just for context, I'm using perl 5.6.1, HTML::Template 2.6, with "use strict"}. Ideally, I want to add a line at a time to that array, and then pass that whole array to the param. So, I tried various things: # attempt 1 my @test = (); push @test { name=>"foo",value=>"blitz" }; # Gets "Global symbol "%test" requires explicit package name at ...[push line]" !?!?! there is no %test. # attempt 2 my @test = (); push @test \{ name=>"foo",value=>"blitz" }; # Gets "Backslash found where operator expected at ...[push line]" # attempt 3 my @test = (); push @test [ { name=>"foo",value=>"blitz" } ]; # Gets "Type of arg 1 to push must be array (not array slice) at ...[push line]" [more stuff along the same lines that didn't work...] *grrr* Okay, says I, I'll work on something else and wait for the muse to strike. I decide I'll figure out how to pass an array into a param... # attempt 4 my @test = [ { a=>"b",c=>"d" }, { e=>"f",g=>"h" }, ]; $template->param(itemloop => [EMAIL PROTECTED]); # Gets "HTML::Template->output() : fatal error in loop output : HTML::Template->param() : Single reference arg to param() must be a has-ref! You gave me a ARRAY. at ..." # attempt 5 my %test; $test{"a"}="b"; $test{"c"}="d"; $test{"e"}="f"; $template->param(itemloop => \%test); # Gets "HTML::Template::param() : attempt to set parameter 'itemloop' with a scalar - parameter is not a TMPL_VAR! at ..." # attempt 6 my %test; $test{"a"}="b"; $test{"c"}="d"; $test{"e"}="f"; $template->param(itemloop => %test); # Gets "You gave me an odd number of parameters to param()! at ..." Ach. So, no better luck. Clearly there's some simple skullduggery I'm missing here. Can anyone enlighten me? Pointers to documentation would be fine, though the HTML::Template page and the perldoc for HTML::Template didn't help too much already. -Ken ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ Html-template-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/html-template-users Jefferies archives and reviews outgoing and incoming e-mail. It may be produced at the request of regulators or in connection with civil litigation. Jefferies accepts no liability for any errors or omissions arising as a result of transmission. Use by other than intended recipients is prohibited. ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ Html-template-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/html-template-users