ysth has asked for the wisdom of the Perl Monks concerning the following question:
None of those work. This works, but marks all the globs in the stash as FAKE, with disastrous consequences:*foo = *bar; *foo = Symbol::gensym *foo = \*bar; local *foo;
Any clues short of XS?%pkg:: = (foo => *bar, %pkg::);
Update: Ok, the obvious solution finally occured to me:
except that there seems to be no way to restore the glob to its original state. The above will put it at a different memory location.package pkg; $save_old_foo = \*foo; delete $pkg::{foo}; *{"pkg::foo"} or 0; # make perl create a new glob ...code using replaced glob goes here... delete $pkg::{foo}; *pkg::foo = $save_old_foo;
Update: judging by votes, I seem to have intrigued some people. My end use ended up somewhat pointless in the end, but I may post a meditation on it when I have some time. It involved sub {}'s undocumented interaction with *__ANON__.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: creating a new symbol table glob
by jql (Acolyte) on Nov 03, 2003 at 00:53 UTC | |
by ysth (Canon) on Nov 04, 2003 at 12:49 UTC | |
by Anonymous Monk on Nov 05, 2003 at 04:32 UTC | |
by jql (Acolyte) on Nov 05, 2003 at 04:39 UTC |