Can perl do multiplying a string like python? [duplicate]

六月ゝ 毕业季﹏ 提交于 2021-02-18 09:08:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!