in reply to Concatenating more than one variable in perl
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, |
|
|---|