eval

Evaluate string as Object without eval() dynamically?

EDIT: Thanks Kenny and everyone else who answered similarly. It really was a DOH...So stupid of me not to remember this. Maybe the answer is so simple it's eluding me...but I know someone here can school me on this hopefully. So I've got a rather large project that's dealing with tons of very large JSON, Objects, Arrays, etc..And I ne...

Parsing JSON from AJAX, potential man in the middle with eval?

I'm writing some AJAX; the server returns JSON (that I also wrote, and as such is sanitary JSON). Under these conditions it seems I can use eval just fine, however I worry that there may be some sort of man in the middle attack on my clients, substituting their JSON for mine. I suppose if there is a man in the middle, they can just as ea...

PHP - templating with custom tags - is this a legit use of eval?

Overview Around the end of 2009, I wrote a simple templating system for PHP/HTML to be used in-house by our designers for brochure-ware type websites. The goal of the system is to allow templating in otherwise pure HTML via custom tags that are processed by PHP. For example, a templated page might look like this: <tt:Page template="tem...

Struggling with flashlite 1.0 Strings

I'm using eval to simulate arrays. Setting values works fine for integers, but seems to completely fail for strings. eval("array" add i-1) = arrayVal; // fails for string values Getting values seems to work perfectly fine either way. arrayVal = eval("array" add i-1); // works fine for strings and ints Is there any way around this?...

Iterating over json object without using eval?

Sorry, this is probably a duplicate question, but how can I iterate over a list in Javascript inside another object without using eval()? See pseudocode in CAPITALS below: polygon = polygon['coordinates']; //list object var polygon = new CM.Polygon([ FOR POLY IN POLYGON { new CM.LatLng(poly[1], poly[0]), } ]); Obviously, I ...

Why the open quote and bracket for eval('(' + jsonString+ ')') when parsing json string

Can you please tell me the reason for this specific syntax structure eval('(' + jsonString+ ')') When parsing json text. Crockford says "The text must be wrapped in parens to avoid tripping on an ambiguity in JavaScript's syntax." here. What does that mean? Can we avoid it? ...

Evaluate string as formula in cell in Excel 2007

Hello. I haven't had any luck finding an eval-type function to use in a cell for Excel. Let's say I have a cell A1 that contains string "C4". I'd like to be able to write an in-cell function similar to this IF(EVAL(A1)>10,"TOO BIG","TOO SMALL"). That would then effectively be C4>10 for the expression. Is this possible without VBA? ...

eval() and PHP errors

Hi I have a eval function like this if(FALSE === @eval($code)) echo 'your code has php errors'; So if the code has synthax errors it will return that message. The problem is that if within the code you have something like: require_once('missing_file.php'); it will just break the page, without my nice error message :( Is there ...

asp Eval function

Hi can i save the returning value of eval function in a variable and use it wherever i want? i can call it just in <asp: .... tags. i can't use them in vb methods. is it possible? ...

Simultaneous eval and exec

Is there a way to get python to do an evaluation and execution on a string? I have a file which contains a bunch of expressions that need to be calculated, maybe something like this. f1(ifilter(myfilter,x)) f2(x)*f3(f4(x)+f5(x)) I run through the file and eval the expressions. Some of the expressions may want to save their work afte...

clojure resolving function from string name

In clojure 1.2RC1, I wish to obtain a function based on its name as string and evaluate it. Function definition (ns my-ns) (defn mycar [x] (first x)) The following worked: ((ns-resolve *ns* (symbol "mycar")) '(3 4)) ((intern *ns* (symbol "mycar")) '(3 4)) ((eval (symbol "mycar")) '(3 4)) but they seem ugly. Is there a better wa...

How come eval doesn't have access to the scoped variables under a with statement?

Why can't you access scoped variables using eval under a with statement? For example: (function (obj) { with (obj) { console.log(a); // prints out obj.a eval("console.log(a)"); // ReferenceError: a is not defined } })({ a: "hello" }) EDIT: As the knowledgeable CMS pointed out, this appears to be a browser bug (brow...

How to do this without eval()

for (var i in variables) { eval('var ' + i + ' = variables[i]'); } Basically, I want to transfer variables properties to local variables. Is there an alternative to using eval() Or which of these is better: 1. var _ = variables; for (var i = 0; i < 100000; i++) { _.test1(); _.test2(); _.test3(); } 2. with (variab...

Calling code in a string without exec/eval, python

I have this code that executes when a player attempts to eat something: def eat(target='object'): global current_room global locations global inventory if target in inventory: items[target]['on_eat'] #This is showing no results. else: print 'You have no ' + target + ' to eat.' and this code for item...

A question about eval() in javascript... why is it evil and how can I accomplish the same thing without using it?

I have an application script that is working correctly, but I have a few eval() statements in order to make things work. I don't really understand why "eval is evil", as I keep reading, but what I really don't understand is how to avoid using it when it's the only thing that does what I need it to do. In my script, I have a bunch of pro...

Casting Eval("bitValue") as Bool

I have a list view with a HyperLink control within the ItemTemplate. I want to display the link if a returned value is 0 (false), and not display the link if it is 1 (true). So far I have this: <asp:HyperLink runat="server" ID="lnkReview" NavigateUrl='<%# Eval("EnquiryID", @"selectcompany.aspx?enq={0}")%>' Text="Review Enquiry" V...

eval in if statement?

<% if(Eval("SaveDate") != DBNull.Value){ %> do magic <%} %> gives me error: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. I could write : <%# Eval("SaveDate") != DBNull.Value ? do magic But I need to do lots of html magic in if statemen...

How can I output this dynamic data without eval?

I've been writing a CMS in MVC style and have used a Template class to pull in the various files required via file_get_contents At the end I do eval('?>'.($template).'<?'); Knowing that eval is evil, how can I alternatively flush this data so the PHP actually renders the code? At the moment the Template class does this once everythi...

Dynamically execute a function in JavaScript

Hi, I would like to call a function whose name I have in a variable. For example: I get the string "pageTracker._trackpageview('/url/page1.page'); " dynamically and assign it to a variable as below var myFunction = pageTracker._trackpageview('/url/page1.page');"; Now when I submit the page I want to execute the function which is i...

How do I evaluate PHP string as a variable?

I have a variable named $data["main_deal"] that has the value $xml->deals->deal[0] (as a string). $xml is a simpleXML object, and the value of main_deal is the selector needed to access the data I want. When I tried echo "<p><b>Main Deal:</b> ".$data["main_deal"]; it output: Main Deal: $xml->deals->deal[0] So I went back to where I gav...