If you want to concatenate the same text to each variable, just use a for loop:

23:50 >perl -wE "my ($var1, $var2) = ('Hi', 'Hello'); $_ .= ' world' f +or $var1, $var2; say qq[$var1, $var2];" Hi world, Hello world 23:53 >

But it looks like you want to concatenate a different piece of text to each variable; in which case, maybe this is what you’re looking for:

use strict; use warnings; my @vars = qw[Hi Hello Greetings ]; my @suffixes = qw[there world earthlings]; @vars = map { $_ . ' ' . shift(@suffixes) . '!' } @vars; print join(', ', @vars), "\n";

Output:

0:06 >perl 923_SoPW.pl Hi there!, Hello world!, Greetings earthlings! 0:06 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Concatenating more than one variable in perl by Athanasius
in thread Concatenating more than one variable in perl by manoj_speed

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.