我在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中相当高级的话题。