perltemplate-toolkit

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" %]

Solution

  • 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 %]