Aliasing symbol table entries does not work unless the aliasing assignment is executed by code in a different package. Why is this? BEGIN{ *main::mainvar = *someotherpkg::whatever } does not define $mainvar in package main if that assignment is executed in package main... or so it seems (see demo script below).
Can someone explain what is going on here? I've read 'perlmod' carefully and think I understand Perl symbol tables. But.
#!/usr/bin/env perl use strict; use warnings; use feature qw/say/; package Foo; our $foovar; BEGIN{ $foovar = 42 } package main; # This does not work (gets "Variable $mainvar is not imported") BEGIN{ package main; *main::mainvar = \$Foo::foovar; } # But this does work ... why? #BEGIN{ package xyzzx; *main::mainvar = \$Foo::foovar; } say $mainvar;
In reply to Why don't *glob assignments affect the current pacakge? by jimav
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |