Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Dynamic USE and %INC

by nobull (Friar)
on Mar 29, 2005 at 16:19 UTC ( #443173=note: print w/replies, xml ) Need Help??


in reply to Re^2: Dynamic USE and %INC
in thread Dynamic USE and %INC

Care to explain why I wouldn't want to use eval in this case?

Mostly it's instinct. Using eval mixes up program space a dataspace even more than symrefs. Where there are two solutions of equal complexity one using eval(STRING) and the other not then use the one without.

The other nasty thing about eval is that unless you use a #line directive the errors you get just say "in eval 666" or something equally unhelpful.

The example doesn't show but I use eval's result to see if all went well (the variable names and values come from a db that might have garbage in them, causing compilation errors).
But if you didn't constuct a string as pass it to the compiler then there wouldn't be any errors! Why should garbage in the values cause errors? As it happens garbage in the names won't throw any errors either since symbols defined with symrefs can have any name.

Anyhow if the database is not trusted to be valid you definitely should not be passing it to eval() in case it decides to reformat your disk.

You are praising eval(STRING) because it provides you with a solution that it caused.

With my solution all you need to add is a check that $varName !~ /\W/. Actually if there's a chance that the database is truely malicious and not just erroneous then you really should check $varName is not null or one of the special globally global variables.

$varName && $varName !~ /\W/ && \*$varName != \*{"::$varName"}

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2023-10-04 19:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?