Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl Template Toolkit - how to join / concat multiple variables (into one)

Perl Template Toolkit - how to join / concat multiple variables (into one) for example wanting it when selecting the chosen element in a html select field/combo.

I found the question here https://www.perlmonks.org/?displaytype=print;replies=1;node_id=880584 , but it did not seem to be properly replied.

Dots, spaces or plus signs didn't help to join variables.

Edit: previously I managed to work it around just by using interpolation inside a string

[% var = "$var1-$var2-$var3" %]
like image 522
FantomX1 Avatar asked Sep 20 '25 10:09

FantomX1


1 Answers

String concatenation is done with the underscore _. See the manual here. It's a bit hidden.

[%
   SET $foo = $bar _ $asdf _ " " _ $xyz
%]

For your example, that would be done like this, but interpolation works just as well.

[% var = $var1 _ "-" _ $var2 _ "-" _ $var3 %]
like image 135
simbabque Avatar answered Sep 22 '25 04:09

simbabque