将数组传递给Perl sub时,“太多参数”
发布时间:2020-12-15 21:17:43 所属栏目:大数据 来源:网络整理
导读:我在perl中有一个函数 sub create_hash(){my @files = @_; foreach(@files){ if(/.text/) { open($files_list{$_},"$_") || die("This file will not open!"); } }} 我通过传递一个数组参数来调用这个函数,如下所示: create_hash( @files2); 该数组中有大
我在perl中有一个函数
sub create_hash() { my @files = @_; foreach(@files){ if(/.text/) { open($files_list{$_},">>$_") || die("This file will not open!"); } } } 我通过传递一个数组参数来调用这个函数,如下所示: create_hash( @files2); 该数组中有大约38个值。 Too many arguments for main::create_hash at .... 我在这里做什么错? 我的perl版本是: This is perl,v5.8.4 built for i86pc-solaris-64int (with 36 registered patches,see perl -V for more detail) 解决方法
你的问题在这里:
sub create_hash() { ()是一个prototype.在这种情况下,它表示create_hash不带参数。当你尝试传递一些,Perl抱怨。 应该看起来像 sub create_hash { 一般来说,you should not use prototypes with Perl functions.他们不像大多数其他语言的原型。他们有使用,但这是Perl中相当高级的话题。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |