in reply to unloading code

If you eval a file (like with require), new subroutine definitions will replace old ones, usually just fine. Coderefs taken to old routines still refer to the old routines, however, and closures for those routines will remain alive.

If you want something fancier, perhaps you can "delete" the entire package. I've seen code to do that somewhere (perhaps even here).

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: unloading code
by premchai21 (Curate) on Oct 07, 2001 at 22:01 UTC

    Curious... it seems that perl dumps core when undefing packages.

    Foo.pm contains:

    package Foo; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(hello say); @EXPORT_OK = qw(hello say); sub hello { "Hello, world!\n"; } sub say { print @_; }

    If I do this (not including extraneous output):

    $ perl -MFoo -de 42 > x %Foo:: (contents of Foo package) > say hello Hello, world! > undef %Foo:: > x %Foo:: empty array > say hello

    ... abort with SIGSEGV in DB::DB. If I run this outside the debugger, it works fine. Running perl 5.6.1 on i686-pc-linux-gnu.