eval

Why is it a bad habit to parse and evaluate a string code (in R)? [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 17:48:51
问题 This question already has answers here : What specifically are the dangers of eval(parse(…))? (4 answers) Closed 6 years ago . I've been told that it is a bad habit to parse and evaluate a character string to_run = "for (i in 1:10){print(i);print('Hello World!')}" eval(parse(text=to_run)) Why is it a bad habit? It seems to me to be quite a flexible way of programming as we can construct our code in a iterative manner by pasting character strings together. For example it allows to easily deal

PHP function in XML?

為{幸葍}努か 提交于 2019-12-24 14:34:42
问题 Is it possible to write a PHP function in a XML <doThis> doThis(){ bang bang bang! } </doThis> and use simplexml_load_file to get the object with that function? $foo = simplexml_load_file($xmlAbove); $foo->doThis(); //bang bang bang! 回答1: Firstly, you should always consider the security implications of running "code" like this. If this XML file has remote origins, and you execute the code, then it might do anything. What about exec(rm -fR /some/important/path); ? Or a database call that

Read in and merge many CSV files into data.table

China☆狼群 提交于 2019-12-24 13:34:11
问题 I have many .csv files, containing variables for the same "population", keyed by surname and first.name . So every csv has three columns: first name, surname and the variable of interest. I load each one of them in separate data tables which then I want to merge them. library(data.table) surnames <- c('A', 'B') first.names <- c('C', 'D') weights <- c(80, 90) heights <- c(180, 190) write.csv(data.frame(surname = surnames, first.name = first.names, height = heights), file = 'variable-height.csv

Updating a data.frame column with eval function

白昼怎懂夜的黑 提交于 2019-12-24 12:33:52
问题 I have a data.frame df with 2 columns in R and I need to update one of the columns by using a eval function (or by any other way) based on the values in the other column. Col1 is a character column and I need to evaluate the expression and update the result in Col2 . So, for the first row it would be -0.49, for the last one: -0.26. I tried this approach but it updates all the values with the result from last row's evaluation: df["Col2"] <- eval(parse(text=df$Col1)) Col1 Col2 -----------------

Chrome app eval()

时光怂恿深爱的人放手 提交于 2019-12-24 11:32:24
问题 I am trying to create a simple calculator for chrome. I need to use eval() to evaluate the expression,but it is banned by chrome. Any workarounds? Here is the js. Can anyone give a solution to this? I have looked everywhere. var text = document.getElementById("tBox"); var x = 0; var y = 0; var op = ""; var resetFlag = 0; document.getElementById("buttonbackspace").addEventListener("click",function(){backspace()}); document.getElementById("buttonone").addEventListener("click",function()

Can php eval return a boolean value?

本小妞迷上赌 提交于 2019-12-24 09:49:25
问题 I cant seem to get eval to return a boolean value for '(4 > 5)' Is this possible? If not how might I get this to work (without writing a parser) I have tried this: $v = eval('return (10 > 5)'); var_dump($v); // Result = bool(false) UPDATE Thanks to @Pekka - I added a semicolon to the above code and it works. 回答1: See the manual: eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned . If there is a parse error in the evaluated

Launching 'safe' eval()

三世轮回 提交于 2019-12-24 07:38:00
问题 I m making a irc bot https://github.com/mouuff/MouBot I would like the bot to reply the eval() when the message starts with !math but its creating failures if the user enter something like !math exit() and stuff like that 回答1: Don't. It looks like you are trying to create a math parser. Then use a math parser, not a full-fledged I-will-run-any-code-parser. If you are using *nix, you could use a program like bc to do what you want. 回答2: Use the language services to compile it into an AST, walk

Parsing functions stored as strings in object literal/JSON syntax and differetiating

孤街醉人 提交于 2019-12-24 05:52:02
问题 There is a previous question (here), however the answers there does not answer my question exactly - the accepted answer contained invalid JSON (mandating the use of eval() ), which is simply not possible to do even something like that as far as I am aware. I'm planning to use code from my own server that is stored as object literal syntax in a string, however I'd like the ability to store functions in there as well. Currently, I've thought of the following possibilities: Simply use eval() to

Parsing functions stored as strings in object literal/JSON syntax and differetiating

点点圈 提交于 2019-12-24 05:50:15
问题 There is a previous question (here), however the answers there does not answer my question exactly - the accepted answer contained invalid JSON (mandating the use of eval() ), which is simply not possible to do even something like that as far as I am aware. I'm planning to use code from my own server that is stored as object literal syntax in a string, however I'd like the ability to store functions in there as well. Currently, I've thought of the following possibilities: Simply use eval() to

How can I gzinflate and save the inflated data without running it? (Found what I think is a trojan on my server)

爱⌒轻易说出口 提交于 2019-12-24 03:41:28
问题 Well, not my server. My friend found it and sent it to me, trying to make sense of it. What it appears to be is a PHP IRC bot, but I have no idea how to decode it and make any sense of it. Here is the code: <?eval(gzinflate(base64_decode('some base 64 code here')))?> So I decoded the base64, and it output a ton of strange characters, I'm guessing either encrypted or a different file type, like when you change a .jpg to a .txt and open it. But I have no idea how to decode this and determine