小编rya*_*anm的帖子

参数的意外自动更新

显然,我对无自动修复实用程序的理解是不完美的,因为以下脚本的非线性 19行为对我来说是非常令人惊讶的.

use 5.014;
use strict;
use warnings;
no autovivification qw(fetch exists delete warn);

{
  my $foo = undef;
  my $thing = $foo->{bar};

  # this does not die, as expected
  die if defined $foo;
}

{
  my $foo = undef;
  do_nothing( $foo->{bar} );

  # I would expect this to die, but it doesn't
  die unless defined $foo;
}

sub do_nothing {
  return undef;
}
Run Code Online (Sandbox Code Playgroud)

运行脚本会产生:

Reference was vivified at test.pl line 8.
Run Code Online (Sandbox Code Playgroud)

问题:为什么$foo$foo->{bar}作为sub的参数提供时自动生成,即使 …

perl autovivification

11
推荐指数
1
解决办法
231
查看次数

标签 统计

autovivification ×1

perl ×1