我试图将参数传递给perl子例程,并且无论出于何种原因,子例程中的参数都是空的。Perl将参数传递给子例程不起作用
...
...
...
print "Passing arguments $a, $b, $c, $d \n";
beforeEnd($a, %b, $c, $d);
sub beforeEnd() {
my ($a, %b, $c, $d) = @_;
print "a is $a, b is $b, c is $c, d is $d \n";
}
打印语句的输出给了我一个想法,即某些错误。奇怪的部分?前两个参数正确传递。
> Passing arguments 1, (1,2,3), 2, 3
> a is 1, b is (1,2,3), c is , d is
任何帮助将不胜感激。
您正在传递'%b',但是正在打印'$ b'。 – Barmar 2015-03-30 19:22:08
赋值中的列表变量将接收函数的所有其余参数。 – Barmar 2015-03-30 19:23:12
如果要传递列表而不将其作为单独的参数传播出去,则应该使用数组引用。 – Barmar 2015-03-30 19:24:37