in reply to Aggregating text and variables into a new variable

There are several ways:
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.

Replies are listed 'Best First'.
Re^2: Aggregating text and variables into a new variable
by finhagen (Sexton) on Nov 30, 2008 at 00:02 UTC
    Thank you for your thorough reply. My problem is solved.
    Hagen
      It would be nice if you shared with us how you solved it. Someone else might learn something from it reading this thread.