如何在Perl中重复一次字符串N次?
在Python中,如果我这样做:
print "4" * 4 我明白了 > "4444" 在Perl中,我会得到 > 16 在Perl中有一个简单的方法来做前者吗? 解决方法$perl -e 'print "4"x4; print "n"' 4444 在perldoc perlop中记录了x运算符.这里二进制意味着一个运算符采用两个参数,而不是由位组成.
print ’-’ x 80; # print row of dashes print "t" x ($tab/8),’ ’ x ($tab%8); # tab over @ones = (1) x 80; # a list of 80 1’s @ones = (5) x @ones; # set all elements to 5 perl -e用于从命令行执行perl代码: $perl --help Usage: perl [switches] [--] [programfile] [arguments] -e program one line of program (several -e's allowed,omit programfile) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |