You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"local %MYPKG::;" causes $MYPKG::FOO and ${"MYPKG::FOO"} to differ #816
Here's a program that uses the statement "local %MYPKG::;", and then
finds that the variables $MYPKG::FOO and ${"MYPKG::FOO"} have
different values.
I don't see how this can ever correctly happen to a package variable.
The address of $MYPKG::FOO is known at compile-time.
The address of ${"MYPKG::FOO"} is not.
Therefore the local() is screwing the latter but not the former.
Activity
p5pRT commentedon Nov 4, 1999
From rnewman@northernlight.com
It prints the following output:
"" ""
"green" "green"
"red" "red"
"red" ""
"blue" ""
"blue" "yellow"
"blue" "blue"
when it should, in my opinion, print this:
"" ""
"green" "green"
"red" "red"
"" ""
"blue" "blue"
"yellow" "yellow"
"red" "red"
#!/usr/bin/perl
use strict;
no strict 'refs';
sub foo {
local %MYPKG:: ;
dumpit();
$MYPKG::COLOR = "blue";
dumpit();
${"MYPKG::COLOR"} = "yellow";
dumpit();
}
sub dumpit {
print qq("), $MYPKG::COLOR, qq(" );
print qq("), ${"MYPKG::COLOR"}, qq("\n);
}
dumpit();
$MYPKG::COLOR = "green";
dumpit();
${"MYPKG::COLOR"} = "red";
dumpit();
foo();
dumpit();
p5pRT commentedon Nov 4, 1999
From [Unknown Contact. See original ticket]
Ron Newman writes:
The address of $MYPKG::FOO is known at compile-time.
The address of ${"MYPKG::FOO"} is not.
Therefore the local() is screwing the latter but not the former.
Short solution: don't do that :-)
Nat