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,
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.