Possible Duplicate:
How can I repeat a string in Perl?
In python
"a" * 4
results in "aaaa"
Can Perl do this too?
It's the repetition (x
) operator.
'a' x 4 # 'aaaa'
The x
operator can also create lists of repeated elements.
('a','b') x 4 # 'a','b','a','b','a','b','a','b'
Using parens (or qw()
) is mandatory if you want to create a list.
Operators are documented in perlop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With