On Wed, 27 Aug 2003, Franco Bagnoli wrote:
> I often deal with structured arrays (LoL), say
>
> [%a = [0, [1,2],[3,4], [4,5,6]] %]
>
> and I need to print them in some form, sometimes just flattened.
>
> Join doesn't do the job, and neither merge (it is undocumented, isn't
> it?)
Franco,
Have you looked at the Data::Dumper plugin (Dumper) for TT2? I
think it will do what you want (in a nicely formated way). Try
this (the <pre></pre> assumes you're in a web context):
[% USE Dumper %]
[% a = [0, [1,2],[3,4], [4,5,6]] %]
<pre>[% Dumper.dump(a) %]</pre>
You could also write a virutal method (as I did) which can
automatically pad the output with <pre></pre> and save you the 'USE
Dumper' call in your template. Here are my virtual methods:
# put this up top in the package that contains all your virtual
# methods
use Data::Dumper;
# define a list method to return a Data::Dumper dump (for debugging)
$Template::Stash::LIST_OPS->{ dump } =
sub {
my $list = shift;
return '<pre>' . Dumper($list) . '</pre>';
};
# define a hash method to return a Data::Dumper dump (for debugging)
$Template::Stash::HASH_OPS->{ dump } =
sub {
my $hash = shift;
return '<pre>' . Dumper($hash) . '</pre>';
};
then to use it in your template:
[% a = [0, [1,2],[3,4], [4,5,6]] %]
[% a.dump %]
I hope that helps.
And as far as I know (though I could well be wrong), there is no
contrib repository for virtual methods.
Take care,
Dave
/L\_/E\_/A\_/R\_/N\_/T\_/E\_/A\_/C\_/H\_/L\_/E\_/A\_/R\_/N\
Dave Cash Power to the People!
Frolicking in Fields of Garlic Right On-Line!
[EMAIL PROTECTED] Dig it all.
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates