Perl (Scripting) - Append values to a variable (.=)

by
Jeremy Canfield |
Updated: March 19 2020
| Perl (Scripting) articles
Let's say you have a variable that contains fruit.
my $fruit = "banana apple orange grape";
The .= operator can be used to append values to the end of the variable. In this example, pineapple will be appended to the $fruit variable.
$fruit .= "pineapple";
After pineapple has been appended, the variable can be printed.
print $fruit;
The original values in the variable plus pineapple will be printed.
banana apple orange grape pineapple
Did you find this article helpful?
If so, consider buying me a coffee over at