Re: How to avoid eval()?
by moritz (Cardinal) on Sep 16, 2011 at 08:00 UTC
|
eval is what you use for the most general case of executing perl commands that you have in a string. Why do you want to avoid it?
As it is, the question is a bit like "I'd like to make a phone call, but without using a phone".
If you only want to allow certain operations, several techniques exist, the best choice depends on what exactly you want to do. For example for only evaluating mathematical expressions safely, modules like Math::Expression::Evaluator exist.
| [reply] [Watch: Dir/Any] |
Re: How to avoid eval()?
by choroba (Cardinal) on Sep 16, 2011 at 07:35 UTC
|
| [reply] [Watch: Dir/Any] |
|
I didn't want to enter in too much detail and as they usually recommand not trusting eval(), I thought it would suffice. The problem is that I loose the well ordering of my recursive set when calling my function through an eval() while it is kept when using a dedicated program to perform the same function. In the past I went into much confusion for problems of this kind till I migrated my recursive functions to C.
| [reply] [Watch: Dir/Any] |
|
What you wrote doesn't make any sense (or maybe only in some context that is not apparent from this discussion thread)
I don't see how using eval() would destroy any order, and there's no code to demonstrate it.
Oh, and sets are unordered by definition.
| [reply] [Watch: Dir/Any] |
A reply falls below the community's threshold of quality. You may see it by logging in.
|
|
I highly doubt that you mean what you say when you use words like Well Ordering a Recursive Set.
Maybe you really want to show us the relevant part of your code as a self-contained program. Please also do show what input data you give it and what output you get and what output you expect.
| [reply] [Watch: Dir/Any] |
|
A reply falls below the community's threshold of quality. You may see it by logging in.
|
Re: How to avoid eval()?
by bart (Canon) on Sep 16, 2011 at 10:43 UTC
|
There are two kinds of eval:
- eval STRING
This takes a piece of string and executes it as Perl code. This is the bad kind.
- eval BLOCK
This is Perl's equivalent for try/catch in other languages, and there's nothing wrong with it.
What kind of eval are you talking about?
update Duh! You're talking about executing user supplied code, so of course it's eval STRING.
Well, there's no way to avoid executing user supplied code if you want to execute user supplied code.
Either you eval the input as Perl, or you provide a small language (not Perl) and interpret it, in Perl. The latter is safer, but a lot of work to implement.
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: How to avoid eval()?
by Anonymous Monk on Sep 16, 2011 at 07:46 UTC
|
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
Re: How to avoid eval()?
by BrowserUk (Patriarch) on Sep 16, 2011 at 09:47 UTC
|
if( 0 ) {
eval <>;
}
| [reply] [Watch: Dir/Any] [d/l] |
Re: How to avoid eval()?
by ambrus (Abbot) on Sep 16, 2011 at 08:46 UTC
|
| [reply] [Watch: Dir/Any] |
A reply falls below the community's threshold of quality. You may see it by logging in. |