in reply to Generating HTML from a Hashref of Hashrefs
use strict; use warnings; use Template; #you would normally take this from a file my $template = join "", <DATA>; #some sample data my %data = ( title => "My Albums", albums => [ { artist=>"Some Musician", songs=> [ "Some Song", "Some Other Song", ] }, { artist=>"DocMarten", songs=> [ "The Doc goes wild", "Heavy Shoes", ] } ] ); #create template object and execute template my $tt = Template->new(); $tt->process (\$template, \%data, "myfile.html"); __DATA__ <html> <head> <title>[% title %]</title> </head> <body> [% FOR album = albums %] <h1>[% album.artist %]</h1> [% FOR song = album.songs %] <h2>[% song %]<h2> [% END %] [% END %] </body>
<html> <head> <title>My Albums</title> </head> <body> <h1>Some Musician</h1> <h2>Some Song<h2> <h2>Some Other Song<h2> <h1>DocMarten</h1> <h2>The Doc goes wild<h2> <h2>Heavy Shoes<h2> </body>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Generating HTML from a Hashref of Hashrefs
by rje (Deacon) on Oct 07, 2005 at 20:54 UTC |