String Operators
-
In Perl, there are two ways to concatenate a string:
-
If you are printing it, simply include the string scalar in double quotes.
Example:
print "Welcome back $salutation $firstName $lastName";
-
Remember, single quotes will return the string verbatim, but double quotes
will evaluate the contents of the string and return the result.
-
Otherwise, use the period:
$fullName = $firstName . $lastName;
$maleFullName = "Mr." . $firstName . $lastName;
-
You can easily repeat a string in Perl by using the letter x and the number
of times you wish to repeat the desired string.
$cheer = "Go Bearcats! " x 3;
-
Interestingly, you can also use * to do the same thing.
Give it a whirl!
Home