Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Format and Join an Array in a Template

by mscharrer (Hermit)
on Jun 22, 2009 at 14:51 UTC ( [id://773652]=note: print w/replies, xml ) Need Help??


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) +; };

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://773652]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-23 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found