in reply to undefing *foo{CODE} does not fully work

It seems to work if you undefine *foo instead of undefining $x. If you want to undefine something, you have to undefine it (and not undefine something else).

print "Undefining foo()"; undef *foo; print "Foo is not defined" unless defined &foo;
--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review

Replies are listed 'Best First'.
Re^2: undefing *foo{CODE} does not fully work
by ikegami (Patriarch) on Apr 13, 2006 at 05:03 UTC

    While that and works, it also undefines @foo, %foo, etc. It seems to me that the OP is trying to undefined &foo specifically.

    Other working solutions with the same caveat:

    my $x = \*foo; undef *$x;

    and

    my $x = 'foo'; { no strict 'refs'; undef *$x; }

    and

    my $x = do { no strict 'refs'; \*{'foo'} }; undef *$x;
A reply falls below the community's threshold of quality. You may see it by logging in.