显然我的理解了 没有自动化 pragma是不完美的,因为以下脚本的非线性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;
}
运行脚本会产生:
Reference was vivified at test.pl line 8.
问题是:为什么 $foo
自动化时 $foo->{bar}
作为sub的参数提供,即使 no autovivification
有效吗?