How can I repeat a string N times in Perl?

后端 未结 6 1911
南方客
南方客 2020-12-28 11:50

In Python, if I do this:

print \"4\" * 4

I get

> \"4444\"

In Perl, I\'d get

> 16
         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 12:11

    In Perl, you want to use the "x" operator.

    Note the difference between

    "4" x 4
    

    and

    ("4") x 4
    

    The former produces a repeated string:

    "4444"
    

    the latter a repeated list:

    ("4", "4", "4", "4")
    

提交回复
热议问题