in reply to Nested loops in HTML::Template
I didn't test the code yet, but think that it's somewhat close to what you'd want your data structure to look like. Also, I had to change the names you chose for your loops to make things a bit more clear ;-). See, it is already obvious that 'outter_file_loop' is infact an 'outer' loop since it is outside of the 'inner' loop. What is not obvious, however, is what kind of data that loop is 'cycling' through. So, by naming that as 'dir row' I know that the outer loop is in fact cycling through directories whereas the 'inner' loop (which I named 'file_row') cycles through list of files (5 files) in that directory.use strict; use HTML::Template; # use File::Find; # use File::Find's wanted() method to gather # all directories/files... my $dir_list = [ { dir => 'foo', dir_row => [ { file_row => [ { filename +=> 'foo0.pic' }, { filename +=> 'foo1.pic' }, { filename +=> 'foo2.pic' }, { filename +=> 'foo3.pic' }, { filename +=> 'foo4.pic' } ] # for fil +e_row } ] # for dir_row }, { dir => 'bar', dir_row => [ { file_row => [ { filename +=> 'bar0.pic' }, { filename +=> 'bar1.pic' }, { filename +=> 'bar2.pic' }, { filename +=> 'bar3.pic' }, { filename +=> 'bar4.pic' } ] # for fil +e_row } ] # for dir_row } ]; my $tmpl = new HTML::Template(type => 'filehandle', source => *DATA); $tmpl->param(dir_list => $dir_list); print $tmpl->output(); print "here\n"; __DATA__ <html> <head> <title><TMPL_VAR NAME="title"></title> </head> <body> <center> <table> <TMPL_LOOP NAME="dir_list"> <tr> <th colspan="5" bgcolor="#E0E0E0"><font size="+3"> <TMPL_VAR NAME="dir"></font></th> </tr> <TMPL_LOOP NAME="dir_row"> <tr> <TMPL_LOOP NAME="file_row"> <td colspan="5"><TMPL_VAR NAME="filename"></td> </TMPL_LOOP> </tr> </TMPL_LOOP> </TMPL_LOOP> </table> </center> </body> </html>
<html> <head> <title></title> </head> <body> <center> <table> <tr> <th colspan="5" bgcolor="#E0E0E0"><font size="+3"> foo</font></th> </tr> <tr> <td colspan="5">foo0.pic</td> <td colspan="5">foo1.pic</td> <td colspan="5">foo2.pic</td> <td colspan="5">foo3.pic</td> <td colspan="5">foo4.pic</td> </tr> <tr> <th colspan="5" bgcolor="#E0E0E0"><font size="+3"> bar</font></th> </tr> <tr> <td colspan="5">bar0.pic</td> <td colspan="5">bar1.pic</td> <td colspan="5">bar2.pic</td> <td colspan="5">bar3.pic</td> <td colspan="5">bar4.pic</td> </tr> </table> </center> </body> </html>
Plug this in the code to see your output. Notice here that I have simply added an extra anonymous hash to the dir_row array of the first directory.my $dir_list = [ { dir => 'foo', dir_row => [ { file_row => [ { filename +=> 'foo0.pic' }, { filename +=> 'foo1.pic' }, { filename +=> 'foo2.pic' }, { filename +=> 'foo3.pic' }, { filename +=> 'foo4.pic' } ] }, # for fi +le_row # second row (next batch o +f files of 5) { file_row => [ { filename +=> 'foo5.pic' }, { filename +=> 'foo6.pic' }, { filename +=> 'foo7.pic' }, { filename +=> 'foo8.pic' }, { filename +=> 'foo9.pic' } ] }, # for fi +le_row ] # for dir_row }, { dir => 'bar', dir_row => [ { file_row => [ { filename +=> 'bar0.pic' }, { filename +=> 'bar1.pic' }, { filename +=> 'bar2.pic' }, { filename +=> 'bar3.pic' }, { filename +=> 'bar4.pic' } ] } # for fil +e_row ] # for dir_row } ];
$"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+) +-.*)$/; $_=["ps -e -o pid | "," $2 | "," -v "," "];`@$_`?{print"+ $1"}:{print" +- $1"}&&`rm $1`; print$\;}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Building the structure to hold said beast.
by LTjake (Prior) on May 30, 2002 at 11:54 UTC | |
by vladb (Vicar) on May 30, 2002 at 14:17 UTC | |
by talexb (Chancellor) on May 30, 2002 at 13:57 UTC | |
by LTjake (Prior) on May 30, 2002 at 14:07 UTC |