例如:
my @array = pad_with_zeroes("foo","bar","baz",6);# @array Now eq ("foo",0)
(例如)List :: Util或类似的通用模块中是否还有可以执行此 *** 作的内容?
解决方法my @array = ("foo","baz");my $total_length = 6;push @array,(0) x ($total_length - @array);
从perldoc开始:
Binary “x” is the repetition operator. In scalar context or if the left operand is not enclosed in parentheses,it returns a string consisting of the left operand repeated the number of times specifIEd by the right operand. In List context,if the left operand is enclosed in parentheses or is a List formed by qw/STRING/,it repeats the List. If the right operand is zero or negative,it returns an empty string or an empty List,depending on the context.
作为具有指定用途的子:
sub pad_with_zeroes { my $n = pop; return ( @_,(0) x ($n-@_) ) }总结
以上是内存溢出为你收集整理的在Perl中,如何用零填充数组?全部内容,希望文章能够帮你解决在Perl中,如何用零填充数组?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)