Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Dynamically Changing Packages w/out Eval

by ikegami (Pope)
on Aug 24, 2009 at 13:41 UTC ( #790814=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

A lot simpler and a lot less fragile:

my @overload = ('+' => sub { my $self = shift; my ($other, $info) = @_; # do some stuff }); eval "package $namespace; use overload \@overload; 1" or die $@;


Comment on Re^2: Dynamically Changing Packages w/out Eval
Download Code
Re^3: Dynamically Changing Packages w/out Eval
by betterworld (Deacon) on Aug 24, 2009 at 14:13 UTC
    I thought the original question was how to avoid eval :)
      You can't expect someone to read the OP
      True, but he wanted to avoid eval "because it obfuscates the code". It's clearly the opposite here.

        I avoid eval out of habit. Even if you make sure that you don't eval user input and keep the evaluated code minimal, it's still annoying to debug warnings like "Argument isn't numeric at eval 2718, line 314".

        Though you're right that my code looks a bit obfuscated.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-12-18 03:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls