问题
Possible Duplicate:
How can I repeat a string in Perl?
In python
"a" * 4
results in "aaaa"
Can Perl do this too?
回答1:
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.
回答2:
yes using the x
such as:
> 'a' x 10
for example:
print 'a' x 4;
would do what you want.
来源:https://stackoverflow.com/questions/6024522/can-perl-do-multiplying-a-string-like-python