in reply to Re: creating a new symbol table glob
in thread creating a new symbol table glob

Thanks, I think only something that does local %pkg:: is going to work. Putting everything else back in the local %pkg:: is the next step. Something like this (not yet tested):
my $opkg = \%pkg::; local %pkg::; $_ ne "foo" and *{"pkg::$_"}=$opkg->{$_} for keys %$opkg;
I can't decide if this is so hard because globs are such strange scalars or because symbol tables are such perfectly ordinary hashes.

(About the compile-time lookup of globs, I remember once seeing a quote from Larry complaining about an optimization that made globals faster but not lexicals. Making every global reference look up the glob afresh sure would be a hearty encouragement to always use lexicals. :)

Replies are listed 'Best First'.
Re: Re: Re: creating a new symbol table glob
by Anonymous Monk on Nov 05, 2003 at 04:32 UTC
    Hmm..........
    { $foo::bar = "Show me"; print \*{"foo::bar"}; local %foo:: = %foo::; print \*{"foo::bar"}; print ${"foo::bar"}; # runtime lookup }
    Looks like that's enough. Your big problem is that even changing the glob addresses has no effect in the rest of the program, since perl never looks up symbol-table entries at runtime unless you use a symbolic ref. There is very limited functionality to replacing the glob entries in the symbol-table, since you must use it like a hash in order to see the effect.
      That was me, btw. I forgot to login. Your question was very interesting... I did alot of testing to see how Perl reacts to stash changes like that. Fun and challenging question.