eval

Implementing JS Eval in C#

别来无恙 提交于 2019-12-01 01:28:52
Possible Duplicate: C# eval equivalent? Duplicate of How can I evaluate C# code dynamically? How can we Implement JS eval() in C# If possible provide an example.. thank you You can actually use the JScript eval function from C#... Create a file JsMath.js, with the following JScript code : class JsMath { static function Eval(expression : String) : double { return eval(expression); }; } Compile it into a DLL : jsc /t:library JsMath.js Add a reference to JsMath.dll to your project. You can now use the JsMath class in your code : double result = JsMath.Eval(expression); If you can use C# 3.0 /

How do I learn how to get quoting right in bash?

你说的曾经没有我的故事 提交于 2019-12-01 00:45:07
I'm constantly confused by the rules for quoting and evaluating when I'm writing bash scripts. I know some of the basics, like the difference between '' and "" and ``, but I still seem to get it wrong far too often, and be reduced to experimenting with trying all sorts of different ways to say the same thing. Any individual problem I can usually work out by brute force, but I think my conceptual model of how it works must be hopelessly broken in some unknown way. I have no problem with lisp's quote,eval,read,print,syntax-quote system. In fact I wrote a little kata to help people understand

how to create and assign a value to a variable created dynamically?

江枫思渺然 提交于 2019-12-01 00:40:19
I'm trying to get this to work: function whatever(arg) { eval(arg) + '_group' = []; } The purpose is to have only 1 function instead having three with basically the same content but with different variable names. At the end I want to have something like: a_group = []; b_group = []; Doing this way, I'm getting the error: ReferenceError: Invalid left-hand side in assignment EDIT Here is the original function that I'm trying to make work. But it won't work. function collect_all_values_for(field_name) { switch(field_name) { case 'states': use = 'state'; case 'cities': use = 'city'; case

nested shell variables without using eval

空扰寡人 提交于 2019-12-01 00:21:26
问题 Can I get rid of eval here? I'm trying to set $current_database with the appropriate variable determined by user input (country and action) # User input country="es" action="sales" # Possible variables for current_database final_es_sales_path="blahblah/es/sales.csv" final_en_support_path="yadayada/en/support.csv" final_it_inventory_path="humhum/it/inventory.csv" ... current_database=$(eval echo \${final_${country}_${action}_path}) 回答1: You can use associative arrays, joining the value of both

python3的eval和exec的区别与联系

笑着哭i 提交于 2019-11-30 23:03:17
eval: 可以把字符串里的字符转换为可执行代码,但只支持一行字符。可以返回执行后得到的值。如下: f = "3+6+9+8" s = eval(f) print(s) 输出: "C:\Program Files\python3\python3.exe" D:/codes_py3/luhy_tool/string_utils/mymethod.py 26 exec: 可以把字符串里的字符转换为可执行代码,可以支持多行字符。但是拿不到返回结果。如下: code = ''' def func(): print('test') return 555 func() ''' f = exec(code) print('---'*5) print(f) 输出: "C:\Program Files\python3\python3.exe" D:/codes_py3/luhy_tool/string_utils/mymethod.py test --------------- None 通过exec可以执行动态Python代码,类似Javascript的eval功能; 而Python中的eval函数可以计算Python表达式,并返回结果; (exec不返回结果,print(eval("…"))打印None); 例如: >>> exec("print(\"hello, world\")")

What is the exact meaning of the find2perl perl shebang + eval?

柔情痞子 提交于 2019-11-30 23:02:49
What exacly do the following? #! /usr/bin/perl -w eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0; #$running_under_some_shell the if 0 is never true, so the eval part will never executed, and the eval is strange too - what is the value of $0 in this context (inside single quotes?) Ps: taken from the result of the find2perl command Best guess - as in this comment #$running_under_some_shell , it's to detect if the script is being run by some shell other than perl, e.g. bash. the if 0 is never true, so the eval part will never executed, Not by perl, no. By other shells such as bash it won't spot

JavaEE-实验四 HTML与JSP基础编程

本小妞迷上赌 提交于 2019-11-30 22:57:21
1.使用HTML的表单以及表格标签,完成以下的注册界面( 验证码不做 ) html代码(css写于其中) <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> body{ width: 500px; margin: 10px auto; } form{ display: inline-block; width: 500px; font-size: 10px; border: 1px solid #ccc; padding: 20px; } p{ display: inline-block; margin: 0 5px; color: red; } input{ box-shadow: -1px -1px 1px #888888; padding: 2px 7px; } .text{ display: inline-block; width: 100px; text-align: right; margin-right: 20px; } .line{ margin: 10px auto; } .sex{ width: 45px; } .place{ width: 55px; } .button{ margin-left: 120px;

Why does this string not work with ast.literal_eval

左心房为你撑大大i 提交于 2019-11-30 22:34:11
I get a malformed string error. Here is my testings >>> eval("'Hello:: '+'fdsfds'") 'Hello:: fdsfds' >>> import ast >>> ast.literal_eval("'Hello:: '+'fdsfds'") Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> ast.literal_eval("'Hello:: '+'fdsfds'") File "C:\Python27\lib\ast.py", line 80, in literal_eval return _convert(node_or_string) File "C:\Python27\lib\ast.py", line 79, in _convert raise ValueError('malformed string') ValueError: malformed string From the ast.literal_eval docs : The string or node provided may only consist of the following Python literal

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

99封情书 提交于 2019-11-30 21:56:31
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="templates/main.html"> <tt:Content name="leftColumn"> <p> blah blah </p> ... </tt:Content> <tt:Content name="rightColumn"> <p> blah blah </p> ... </tt:Content> </tt:Page> The template itself might look something like this: <html> <head>...</head> <body> <div style=

枚举应用篇

一世执手 提交于 2019-11-30 21:12:30
《Java编程思想》这本书已经看到19章枚举,之前的很多难点被我略过了。在此章学到了新概念,多路分发。先说说单路分发: Java只支持单路分发,即如果要执行的操作包含多个不确定的类型类型对象时,Java只能处理其中一个的类型。N个未知类型需要N个方法调用以确定其类型即分发。所以编程思想中的多路分发严格讲应该叫“伪多路分发”即多次单路分发。单路分发实质上是多态特性的一种体现。 举个梨子:例如有A、B、C、三种类型a.compete(b),a、b的类型未知,执行此句时只能确定a的类型 代码为证: package com.houjun.enum1; import java.util.Random; /** * @Author: HouJun * @Date: 2019/10/8 17:29 * @Description: 多路分发例子 * @version: 1.0 */ enum Outcome { WIN, LOSE, DRAW; } interface Item { // Outcome compete(Item it);//完成方法 Outcome eval(Paper p); Outcome eval(Scissors s); Outcome eval(Rock r); Outcome eval(Item r); } class Paper implements Item {