How can I repeat a string N times in Perl?

后端 未结 6 1932
南方客
南方客 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:08

    All answers, given so far, missed to mention that the operator x does not only work on string literals but also on string variables or expressions that build strings:

    $msg = "hello ";
    print $msg x 2;
    print ($msg x 2) x 2;
    

提交回复
热议问题