in reply to can you repeat a character N times using HTML::Template?

As others have mentioned, HTML::Template does not support recursion. However, with a very simple change in the HTML::Template source code you can get it to support recursion to a fixed depth!

You can use TMPL_INCLUDE to recursively include itself. When you do this, HTML::Template will die with the following error:

HTML::Template->new() : likely recursive includes - parsed 10 files deep and giving up (set max_includes higher to allow deeper recursion).

So it will only allow 10 levels of include files. But it is configurable with the 'max_includes' parameter that is passed to the constructor.

So all you really need to do to get recursion to work to a given depth is to edit HTML::Template so that is doesn't die when it reaches the 'max_includes' limit. Then when you create the HTML::Template opbject, tell it how many levels deep you want your recursion to go (using max_includes), and then use a template file that uses TMPL_INCLUDE to call itself.

I won't vouch for the efficiency of this method, as each included file is most likely duplicated in memory (ie if you recurse a max of 20 times, you will have 20 parsed copies of the template in memory).

Another way to handle recursion in HTML::Template is to handle it in the code by recursively creating new HTML::Template objects and including the results in other HTML::Template objects using TMPL_VARs.

sub recurse_template { my $template_name = shift; my $template = new HTML::Template(filename => $template_name); my $value = recurse_template('template.tmpl'); $template->params(param => $value); return $template->output(); }

Of course that is an incomplete example, as you would need to stop the recursion at some point, and you probably want to add some parameters at some point... Also, this isn't very efficient either since you are creating and destroying many objects.