in reply to HTML::Template and hash o' links+labels

I have not done this, but the directions seem to indicate something like:
my %hash = ( 'Perl Monks' => 'www.perlmonks.org', 'Gossip and Innuendo' => 'www.salon.com', 'Free Software' => 'www.gnu.org' ); # we need parallel lists for each of the variables my @label_list; my @url_list; foreach my $label ( keys %hash ) { push( @label_list, $label ); push( @url_list, $hash{$label} ); } my @loop_data = (); while (@label_list) { my %row_data = {}; $row_data{'LABEL'} = shift @label_list; $row_data{'URL'} = shift @url_list; push( @loop_data, \%row_data ); } $template->param(THIS_LOOP => \@loop_data); ========== then in the template: <TMPL_LOOP NAME="THIS_LOOP"> Hotlink: <A HREF="<TMPL_VAR NAME="URL">"><TMPL_VAR NAME="LABEL"></ +A><P> </TMPL_LOOP>
But this is a guess. I'd do a Data::Dumper print Dumper( @loop_data ) to get a feel for what this has done. :)

Update: Put while loop around the shift bit, based on repson's input. I overlooked the loop around this section of the sample code in the POD for this module.

Replies are listed 'Best First'.
Re: Re: HTML::Template and hash o' links+labels
by repson (Chaplain) on Dec 21, 2000 at 06:37 UTC
    Don't you want a loop around this block
    # while (@label_list) { $row_data{'LABEL'} = shift @label_list; $row_data{'URL'} = shift @url_list; push( @loop_data, \%rowdata ); # }
    Though I think it is easier to construct @loop_data during your loop over then hash keys instead of creating two lists in the loop and then looping over their elements.