File formats and languages that support eval()

By tom

There is a *simple* and direct method for creating custom file formats for languages that support the eval() function. eval, I use in the javascript sense.

That is, if you need to create a quick way to parse a custom file into your application – take a look at what is supported by eval() and make that work for your situation.

A couple of examples:

1) javascript – a string returned from a webservice can be eval’d directly into a j/s object (called JSON, it’s quite common)

2) actionscript3 – using the JSON parser for actionscript, a response from a webservice or a local config file (using AIR) can be parsed directly into an Object. Object is very similar in usage to the j/s concept of an object.

3) Python – just use the eval() function to convert the string contents of a file directly into a dictionary, list, tuple, or other kind of python object. Useful for a local file format that should be human readable/editable.

4) PHP? Has the capability, though I don’t think I’ve used this idea in solving a problem to date.

I assume that you can trust the content that you are eval’ing. You must take precaution if this is not true.

Leave a Reply