小编Abh*_*rma的帖子

在$ _ [0]的情况下解除引用,$ _ [1] .....等等

请看下面的代码:

$scalar = 10;

subroutine(\$scalar);

sub subroutine {
    my $subroutine_scalar = ${$_[0]}; #note you need the {} brackets, or this doesn't work!
    print "$subroutine_scalar\n";
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,您可以看到写下的注释"请注意您需要{}括号,否则这不起作用!" .请解释为什么我们不能使用相同的声明的原因:

my $subroutine_scalar = $$_[0];
Run Code Online (Sandbox Code Playgroud)

即不使用花括号.

perl

7
推荐指数
1
解决办法
1914
查看次数

标签 统计

perl ×1