Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^2: Dynamically Changing Packages w/out Eval

by betterworld (Curate)
on Aug 25, 2009 at 12:11 UTC ( #791059=note: print w/replies, xml ) Need Help??

in reply to Re: Dynamically Changing Packages w/out Eval
in thread Dynamically Changing Packages w/out Eval

eval "package $package; &$code; 1" or die $@;

I think you're missing a "\" before "$code". But then the code will be called via a code reference, and the contents of the code reference are still in the old package (where they were compiled):

sub run_in_package (&$) { my($code, $package) = @_; eval "package $package; &\$code; 1" or die $@; } run_in_package { showcaller(); } 'foooo'; sub showcaller { warn scalar caller; }

The text of the warning will be "main" (not "foooo").

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://791059]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2016-10-25 13:00 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (319 votes). Check out past polls.