Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Joining an array within a text block

by choroba (Cardinal)
on May 18, 2015 at 16:10 UTC ( [id://1127023]=note: print w/replies, xml ) Need Help??


in reply to Joining an array within a text block

You can shorten foreach to for, or hide it in map:
my $list = join "\n", map "<li>$_</li>", @existing_array;

Or, you can use a templating system:

#! /usr/bin/perl use warnings; use strict; use Template; my @array = ('Item 1', 'Item 2'); my $t = Template->new; my $list = << '__TT__'; <html> <body> <ul>[% FOR item IN list %] <li>[% item %]</li>[% END %] </ul> </body> <html> __TT__ $t->process(\$list, { list => \@array }, \*STDOUT);
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

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

    No recent polls found