One of the first Perl operators to learn is the "dot" concatenation operator (.) for strings. For example:

my $string = 'foo' . 'bar'; # $string is 'foobar'.

my $string = join('', @arr);

Argument "foo" isn't numeric in multiplication (*) at...

my $string = 'foo' x 10;

foofoofoofoofoofoofoofoofoofoo

my $str = 20 x 10; # $str is "2020202020202020202020"





('x','y','z') x 10

('x','y','z','x','y','z','x','y', ...)

my @arr = ('x', 'y', 'z'); my @bar = @arr x 10;

my @bar = scalar(@arr) x 10; # @bar is an array of a single integer (3333333333)

my @foo = ( (@arr) x 10 ); # then @foo is ('x','y','z','x','y','z','x','y', ...)

On the other hand, if you have an array of strings @arr, then you can concatenate them by joining them with an empty string in-between:But what if you just want 10 "foo"s in a line? You might try the Python approach with 'foo' * 10 but Perl with its type conversion on the fly will try to convert 'foo' into a number and say something like:Instead you should use the(x) which takes a string on the left and a number on the right:and $string is thenNote that even if you have integers on both sides, the 'x' repetition operator will cast the left operand into a string so that:Now this isn't all the repetition operator is good for - it can also be used for repetition of lists. For example:evaluates as:But be warned : if the left operand is not enclosed in parentheses it is treated as a scalar.is equivalent towhile, turning the array into a list of its elements by enclosing it in parentheses:In summary, if you remember that 'x' is different to '*' and lists are treated differently to scalars, it's less likely your code will give you an unpleasant surprise!