Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

Possible Duplicate:
How can I repeat a string in Perl?

In python

"a" * 4

results in "aaaa"

Can Perl do this too?

like image 784
funk-shun Avatar asked May 16 '11 23:05

funk-shun


1 Answers

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.

like image 153
ikegami Avatar answered Sep 24 '22 00:09

ikegami