- 论坛徽章:
- 0
|
有以下sub定义:
sub sub1($\@$){
my($var1, $var2, $var3) = @_;
print "var1: ". $var1. "\n";
print "var2: ". $var2. "\n";
print "var3: ". $var3. "\n"; # 如果取返回值,会得到1:print成功
}
我在定义之后调用,总报错:
# error message: Type of arg 2 to main::sub1 must be array (not private variable)
my $array = [1, 2, 3];
sub1('a', $array,'b');
# error message: Type of arg 2 to main::sub1 must be array (not reference constructor)
my @arrya = (1, 2, 3);
sub1('a', \@arrya, 'b');
总不能用这样去调吧:
sub1('a', (1, 2, 3), 'b');
# 地球人都知道这种调法还不如去死... :wink:
谁知道在指定了参数为数组引用的时候怎么调用啊? |
|