Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://791059]
help
Chatterbox?
[kcott]: s/imput/input/
[Corion]: DateTime::Duration ? Personally,I convert stuff to seconds using Time::Piece or Time::Local and then add the seconds and then use POSIX::strftime to print them as hours again
[marto]: good morning all, TCIF
[gnosti]: I'm reading from ffmpeg lengths of video clips in H:M:S and needing to add them and format them back to H:M:S for feeding back to ffmpeg
[marioroy]: kcott Thanks
[Corion]: gnosti: I would cheat and use my approach instead of dealing with durations as objects, or a module
[Corion]: You could even do the calculation directly - my $duration = $H * 3600+ $M*60 + $S; strftime '%H:%M:%S', timelocal($duratio n)
[Corion]: (and that strftime call is largely superfluous too, converting back to H:M:S isn't hard either)

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2017-08-18 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (297 votes). Check out past polls.

    Notices?