autovivification — Lexically disable autovivification. — metacpan.org.
Отменяет autovivification — автоматическое типизирование неопределённого объекта при обращении к нему в каком-нибудь контексте. Используется как
no autovivification;
# !/usr/bin/env perl
use strict; use warnings;
{
my $hashref;
warn ref($hashref);
my $a = $hashref->{key_a}; # $hashref stays undef
warn ref($hashref);
if (exists $hashref->{option}) { # Still undef warn ref($hashref); } warn ref($hashref);
delete $hashref->{old}; # Still undef again warn ref($hashref);
$hashref->{new} = 'test'; # Vivifies to { new => $value } warn ref($hashref);
}
{
no autovivification;
my $hashref;
warn ref($hashref);
my $a = $hashref->{key_a}; # $hashref stays undef
warn ref($hashref);
if (exists $hashref->{option}) { # Still undef warn ref($hashref); } warn ref($hashref);
delete $hashref->{old}; # Still undef again warn ref($hashref);
$hashref->{new} = 'test'; # Vivifies to { new => $value } warn ref($hashref);
}
Leave a Reply
You must be logged in to post a comment.