in reply to Re: Format and Join an Array in a Template
in thread Format and Join an Array in a Template

I now implemented this as follows. I also added alignment of the listed names by calculating the maximum length.

Is there any possibility to get the indention level of the template code, so that all produced lines are indented the same amount (by adding the number of spaces in join( ))?

Thanks again.

Update: I know fixed the indention problem by (re-)adding a join argument:

use Template::Stash; use List::Util qw(max); $Template::Stash::LIST_OPS->{signal_list} = sub { my $aref = +shift || []; my $sep = shift || "\n "; my $l = max map { length $_ } @$aref; join(",$sep", map { sprintf ".%-${l}s (%-${l}s)", $_, $_ } @$aref) +; };