in reply to Defining a subroutine in another package

Just leave eval() out of it. You can write: *{$package . "::foo"} = sub { ... };

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Defining a subroutine in another package
by mirod (Canon) on Jan 26, 2002 at 14:27 UTC

    I believe this only works in perl 5.6.0 and above though.

      It works for me on 5.004_5 and (I presume) even earlier, though you'll have to disable strict 'refs'.

      It's just a symbolic access to a typeglob, nothing special. :)

        I have had problems with it under 5.005: it did not like the sub, although it looked OK and was compiled without a hitch in 5.6.0 and above. So yes the construct works but it looks to me like what you put in the sub can be a problem.

        Here is what caused the problem:

        my( $text_method, $nav); # actually defined and initialized earlier { no strict 'refs'; my ${text_method}= sub { my $elt=shift; my $dest= $elt->$nav( @_) or return ''; return $dest->text; } }