|Welcome to the Monastery|
Trouble with loops in HTML::Templateby Sherlock (Deacon)
|on Jul 10, 2001 at 04:58 UTC||Need Help??|
Sherlock has asked for the
wisdom of the Perl Monks concerning the following question:
I've been using HTML::Template (using jeffa's HTML::Template Tutorial as a reference) for a while now and I've generally had great success using it. Recently, however, while trying to write what I originally thought would be a very simple script, I ran into a problem that I just can't seem to be able to solve. In certain cases, my template is simply failing to produce any output.
I'm attempting to create a simplistic "Tip of the Week" viewer. That viewer will access a file to get each tip. Every tip is on a separate line. For example, this is what my input file might look like:
The most recent tip is the last one in the file so, in this case, "Tip 3" would be the most recent tip, the "Tip of the Week."
I have a simple .tmpl file which I'll use as my template that looks like this:
As you can see, there is a section for the most recent tip along with an area where I can list the archived tips. I'll display the code that I'm using and then try to show you the problem I'm having.
I'm trying to read in all of the tips and put them into an array of hash references, which is what the loop structure in HTML::Template uses. If I have two tips in the file, the script works perfectly. If there is any other number of tips, however, the script fails. Basically, I've narrowed it down to the fact that, if there is only 1 hash reference in @tipList, the script works. If there are more or less, however, it fails.
I've managed to verify, through the following code, that the data is getting into the array @tipList properly:
This code generates something like this for the test file that I gave earlier, which is exactly what I'd expect:
However, there is absolutely no output from my template in that case. Can anyone see what I'm doing wrong here?
Skepticism is the source of knowledge as much as knowledge is the source of skepticism.