Problems? Is your data what you think it is? | |
PerlMonks |
(jeffa) Re: Structure for nested html::template loopsby jeffa (Bishop) |
on Jun 02, 2002 at 01:27 UTC ( [id://170962]=note: print w/replies, xml ) | Need Help?? |
Here is my take on the problem, but first i gotta share
this with you. Take a list of numbers and break them up
into a two dimensional array, each inner array contains,
say 4 elements. Here was my first naive try:
In a nutshell, we iterate through the list. Unless we have reached the 4th element, we store that element in another transitory list. If we have reached the 4th element, we store that list into our outer array. This was the logic i started with trying to solve your problem. It is rather inelegant as i have to push that final transitory array after the loop is finished - and that's what bit me when i applied it to this HTML::Template problem. Now, consider this approach instead: Wow, so much simpler. This takes advantage of Perl's auto-vivification abilities. Instead of depending upon different states, we just do it - and we don't have to worry about clearing a transitory array, but we do have an extra counter for iteration. I'll take that extra counter for ease of programming. So, here is my solution to this larger problem at hand. You will have to make modifications to suite your needs, but this should show you how to do it. I ran this code from my public_html directory on my images directory. That directory contained 3 subdirs with a different numbers of images in each one. I also bundled the template file into the code via the DATA filehandle.
jeffa L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In Section
Seekers of Perl Wisdom
|
|