The final set of operators that we will consider are those that operate specifically on strings. Remember, though, that we can use numbers with them, as Perl will do the conversions to strings when needed.
The string operators that you will see and use the most are
. operator is string concatenation, and the
operator is string duplication.
use strict; my $greet = "Hi! "; my $longGreet = $greet x 3; # $longGreet is "Hi! Hi! Hi! " my $hi = $longGreet . "Paul."; # $hi is "Hi! Hi! Hi! Paul."
It should be duly noted that it is possible to concatenate, like in C, an operator onto the assignment statement to abbreviate using the left hand side as the first operand. For example,
use strict; my $greet = "Hi! "; $greet .= "Everyone\n"; $greet = $greet . "Everyone\n"; # Does the same operation # as the line above
This works for any simple, binary operator.