F
Ferry Bolhar
Hi folks,
While looking at the code in vars.pm (the "use vars" pragma), I tried to
reproduce its behaviour:
use strict;
use vars $x;
$x = 3;
by writing:
use strict;
BEGIN {
*main::x = \$main::x;
}
$x = 3;
instead. However, this code doesnt work, I get the messages
Variable "$x" not imported at line 5
Global symbol "$x" requires explicit package name at line 5
(Line 5 contains the assignment to scalar $x)
However, when including a "package hugo;" in the BEGIN block (or even
outside, and a "package main;" thereafter), the code works as expected. It
also works when the BEGIN block runs in package "main" and the scalar
assignment in a different package. It fails, whenever both assignments
(typeglob and scalar) are executed in the same package.
Can someone explain why? The typeglob assignment occurs full-qualified, so
it shouldn't matter which package is currently active. However, it does.
Why?
Thanks for your answers and kind greetings from Vienna,
Ferry
While looking at the code in vars.pm (the "use vars" pragma), I tried to
reproduce its behaviour:
use strict;
use vars $x;
$x = 3;
by writing:
use strict;
BEGIN {
*main::x = \$main::x;
}
$x = 3;
instead. However, this code doesnt work, I get the messages
Variable "$x" not imported at line 5
Global symbol "$x" requires explicit package name at line 5
(Line 5 contains the assignment to scalar $x)
However, when including a "package hugo;" in the BEGIN block (or even
outside, and a "package main;" thereafter), the code works as expected. It
also works when the BEGIN block runs in package "main" and the scalar
assignment in a different package. It fails, whenever both assignments
(typeglob and scalar) are executed in the same package.
Can someone explain why? The typeglob assignment occurs full-qualified, so
it shouldn't matter which package is currently active. However, it does.
Why?
Thanks for your answers and kind greetings from Vienna,
Ferry