in reply to Reloading Modules

I think the more pressing question is - Why are you needing to reload your modules in this fashion?

Depending on your requirement for this functionality, you could use eval and call your module at run-time only with the scope of this function. eg.

my $func = eval { use MyFunction; return MyFunction->method(); };

The problem with this approach however, is that your module usage will only have a limited scope. Although, depending upon your script design, this could also offer some advantages.

 

 

perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

Replies are listed 'Best First'.
Re: Re: Reloading Modules
by rendler (Pilgrim) on Feb 03, 2002 at 06:18 UTC
    It's an IRC bot and each of the modules extend it's functionality in some way, so it becomes a pain having to restart the thing just to test minor changes.
Re: Re: Reloading Modules
by Anonymous Monk on Feb 03, 2002 at 19:16 UTC
    You don't want to use eval(BLOCK) though. The block is compiled at the surrounding's compile-time. You want eval(EXPR).

    Compare this:
    #!/usr/bin/perl -l print 'pre'; eval { BEGIN { print 'compiling eval block' } }; print 'post';
    with this:
    #!/usr/bin/perl -l print 'pre'; eval q{ BEGIN { print 'compiling eval expr' } }; print 'post';