use strict; # # first # my $var1="fie"; # note closing " my $var2="fum"; my $newvariable="fee $var1 fo $var2"; print "$newvariable\n"; # # second # my $newvariable2= join ' ', 'fee', $var1, 'fo', $var2; print "$newvariable2\n"; # # third # my $newvariable3= <<EOT; fee $var1 fo $var2 EOT print "$newvariable3\n"; # # fourth # my $newvariable4= 'fee ' . $var1 . ' fo ' . $var2; print "$newvariable4\n"; # # fifth # my $newvariable5= 'fee fo '; substr($newvariable5, 8, 0) = $var2; substr($newvariable5, 4, 0) = $var1; print "$newvariable5\n"; # # sixth # my $newvariable6 = pack 'A4A3A4A3', 'fee ', $var1, ' fo ', $var2; print "$newvariable6\n";
see perldoc perlop about interpolation in Quote-and-Quote-like-Operators and concatenation operator .
also please don't forget to use strict; in begin of your scripts
and, imho, the good style is to use single quotes not double quotes for string literals which are not supposed to be interpolated.
In reply to Re: Aggregating text and variables into a new variable
by ccn
in thread Aggregating text and variables into a new variable
by finhagen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |