День добрый.
Локализация $DB::single работает без проблем, но если брать ссылку на неё, то
возникают проблемы:
The localization of $DB::single works fine, but the reference to it does not
work:
{
$DB::single = 7; my $x = \$DB::single;
print "Before: ". \$DB::single ." <<$x $$x\n";
local $DB::single = 0;
print "After: ". \$DB::single ." <<$x $$x\n";
}
The output/Вывод
Before: SCALAR(0x10f8310) <<SCALAR(0x10f8310) 7
After: SCALAR(0x110cbc8) <<SCALAR(0x10f8310) 0
В то время как:
Where as works fine:
{
$DB::z = 7; my $x = \$DB::z;
print "Before: ". \$DB::z ." <<$x $$x\n";
local $DB::z = 0;
print "After: ". \$DB::z ." <<$x $$x\n";
}
The output:/Вывод
Before: SCALAR(0x134d398) <<SCALAR(0x134d398) 7
After: SCALAR(0x1239bc8) <<SCALAR(0x134d398) 7
Тут видно, что в первом примере память выделена: Новый адрес $DB::single
является: SCALAR(0x110cbc8)
Но когда присваиваем новое значение в $DB::single, то значение по старому
адресу ((SCALAR(0x10f8310)) меняется тоже
Во втором примере мы видим, что выделение памяти происходит по той же схеме, но
значение 7 сохранено как и ожидалось.
We see that in *first* example the new variable is created: The new address of
$DB::single is SCALAR(0x110cbc8)
but when assigning to $DB::single the value by old reference (SCALAR(0x10f8310)
changed too.
In *second* example we see that addressing works in same manner, but value 7 is
preserved as expected.
Почему значение $DB::single по старой ссылке меняется?
Why the value of $DB::single by old reference is not preserved?
PS. Можно отвечать на русском.
--
Moscow.pm mailing list
[email protected] | http://moscow.pm.org