Search Results

Search found 1064 results on 43 pages for 'eval'.

Page 6/43 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • Try::Tiny-Question

    - by sid_com
    Why doesn't the subroutine with try/catch give me the same results as the eval-version does. #!/usr/bin/env perl use warnings; use strict; use 5.012; use Try::Tiny; sub shell_command_1 { my $command = shift; my $timeout_alarm = shift; my @array; eval { local $SIG{ALRM} = sub { die "timeout '$command'\n" }; alarm $timeout_alarm; @array = qx( $command ); alarm 0; }; die $@ if $@ && $@ ne "timeout '$command'\n"; warn $@ if $@ && $@ eq "timeout '$command'\n"; return @array; } shell_command_1( 'sleep 4', 3 ); say "Test_1"; sub shell_command_2 { my $command = shift; my $timeout_alarm = shift; my @array; try { local $SIG{ALRM} = sub { die "timeout '$command'\n" }; alarm $timeout_alarm; @array = qx( $command ); alarm 0; } catch { die $_ if $_ ne "timeout '$command'\n"; warn $_ if $_ eq "timeout '$command'\n"; } return @array; } shell_command_2( 'sleep 4', 3 ); say "Test_2"

    Read the article

  • Can I strictly evaluate a boolean expression stored as a string in Java?

    - by D Lawson
    I would like to be able to evaluate an boolean expression stored as a string, like the following: "hello" == "goodbye" && 100 < 101 I know that there are tons of questions like this on SO already, but I'm asking this one because I've tried the most common answer to this question, BeanShell, and it allows for the evaluation of statements like this one "hello" == 100 with no trouble at all. Does anyone know of a FOSS parser that throws errors for things like operand mismatch? Or is there a setting in BeanShell that will help me out? I've already tried Interpreter.setStrictJava(true). Here's the code that I'm using currently: Interpreter interpreter = new Interpreter(); interpreter.setStrictJava(true); String testableCondition = "100 == \"hello\""; try { interpreter.eval("boolean result = ("+ testableCondition + ")"); System.out.println("result: "+interpreter.get("result")); if(interpreter.get("result") == null){ throw new ValidationFailure("Result was null"); } } catch (EvalError e) { e.printStackTrace(); throw new ValidationFailure("Eval error while parsing the condition"); }

    Read the article

  • Eval Smarty Code inside a Smarty Template

    - by clops
    Hi, is there a way to evaluate Smarty Code inside an existing Smarty template? For example, I may have the following construct: smartyTemplate.tpl <body> <div id="dynamicPart"> {$valueFromDatabase} </div> </body> Whereas the Smarty variable $valueFromDatabase contains another Smarty Template which I would like to be inserted in place of the variable and then evaluated as a template (with all the logic expressions in replacements neccessary).

    Read the article

  • PHP preg_replace without eval

    - by Alec Smart
    Am trying to use something like: $newdata = preg_replace($pattern, $replacement, $data); Now my replacement is something like $pattern = "/START(.*?)END/is"; $replacement = "START $config END"; Now, $config contains contents like array('Test\\\'s Page') The problem is that after I write the content, $newdata becomes START array('Test\\'s Page') END As you see above a single \ goes missing because it gets evaluated. How do I avoid that?

    Read the article

  • Python: Dynamic attribute name generation without exec() or eval()

    - by PyNewbie27
    Hi, I'm trying to dynamically create buttons at runtime with PyQT4.7 However, this being my first python program I'm not sure how to get the functionality I want. I would like to be able to substitute a text string for an attribute name: i.e. for each in xrange(4): myname = "tab1_button%s" % each #tab1_button0, tab1_button1, tab1_button2 #self.ui.tab1_button0 = QtGui.QPushButton(self.ui.tab) <--normal code to create a named button setattr(self.ui,myname,QtGui.QPushButton(self.ui.tab)) #rewrite of line above to dynamicly generate a button #here's where I get stuck. this code isn't valid, but it shows what i want to do self.ui.gridLayout.addWidget(self.ui.%s) % myname #I need to have %s be tab1_button1, tab1_button2, etc. I know the % is for string substituion but how can I substitute the dynamically generated attribute name into that statement? I assume there's a basica language construct I'm missing that allows this. Since it's my first program, please take it easy on me ;)

    Read the article

  • Should one bind data with Eval on aspx or override ItemDataBound in code-behind?

    - by George Chang
    For data bound controls (Repeater, ListView, GridView, etc.), what's the preferred way of binding data? I've seen it where people use Eval() directly on the aspx/ascx inside the data bound control to pull the data field, but to me, it just seems so...inelegant. It seems particularly inelegant when the data needs to be manipulated so you wind up with shim methods like <%# FormatMyData(DataBinder.Eval(Container.DataItem, "DataField")) %> inside your control. Personally, I prefer to put in Literal controls (or other appropriate controls) and attach to the OnItemDataBound event for the control and populate all the data to their appropriate fields in the code-behind. Are there any advantages of doing one over the other? I prefer the latter, because to me it makes sense to compartmentalize the data binding logic and the presentation layer. But maybe that's just me.

    Read the article

  • Getting DataBinder Item's max value

    - by iTayb
    I'm working at the aspx page, and the following code is inserted in a Repeater control: <%# ((System.Collections.Generic.List<double>)DataBinder.Eval(Container.DataItem, "BookPrices")).Max() %> Brings up the following error: 'System.Collections.Generic.List<double>' does not contain a definition for 'Max' List does have an method of Max(), so I'm possibly messing up my code somehow. What is my problem? BookPrices is a list<double> object, which I'd like to print it's maximum value. P.S. You guys are great! I didn't find answers for many of my questions on the web. You really are life savers. Thank you very much! :)

    Read the article

  • Perl equivalent to Java's "throws" clausule.

    - by Konerak
    Is there a way in Perl to declare that a method can throw an error (or die)? I always loved how in Java, a method could handle an Exception and/or throw it. The method signature allows to put "throws MyException", so a good IDE/compiler would know that if you use said method somewhere in your code, you'd have to check for the Exception or declare your function to "throws" the Exception further. I'm unable to find something alike in Perl. A collegue of mine wrote a method which "dies" on incorrect input, but I forget to eval-if($@) it... offcourse the error was only discovered while a user was running the application. (offcourse I doubt if there is any existing IDE that could find these kind of things for Perl, but atleast perl -cw should be able to, no?)

    Read the article

  • ruby xmpfilter on windows

    - by dreftymac
    Has anyone out there ever gotten xmpfilter to work on windows? xmpfilter "unterminated string meets end of file" is the error. The only Google hit is in Japanese: google://xmpfilter "unterminated string meets end of file" http://www.unkar.org/read/pc12.2ch.net/tech/1249687283 For background, the desired feature from xmpfilter is to get automatic "eval" annotations of Ruby sourcecode: Before: a = "bravo alpha charlie" # => b = a.split # => b.sort! # => After: a = "bravo alpha charlie" # => "bravo alpha charlie" b = a.split # => ["bravo", "alpha", "charlie"] b.sort! # => ["alpha", "bravo", "charlie"]

    Read the article

  • GWT's JSONParser producing incorrect values for numbers.

    - by WesleyJohnson
    I'm work with GWT and parsing a JSON result from an ASP.NET webservice method that returns a DataTable. I can parse the result into a JSONvalue/JSONObject just fine. The issue I'm having is that one my columns in a DECIMAL(20, 0) and the values that are getting parsed into JSON aren't exact. To demonstrate w/o the need for a WS call, in GWT I threw this together: String jsonString = "{value:4768428229311981600}"; JSONObject jsonObject = JSONParser.parse( jsonString ).isObject(); Window.alert( jsonObject.toString() ); This in turn alerts: {"value":4768428229311982000} I'm under the understanding that GWT's JSONParser is just using eval() to do the parsing, so is this some sort of number/precision issue with JavaScript that I've never been aware of. I'll admit I don't work with numbers that much in JavaScript and I might be able to work around this by changing the .NET WebService to return this column as string, but I'd really rather not do that. Thanks for any help.

    Read the article

  • Perl equivalent to Java's "throws" clause

    - by Konerak
    Is there a way in Perl to declare that a method can throw an error (or die)? EDIT: What interests me the most is a way to get the compiler or IDE to tell me I have an unchecked exception somewhere in my code. I always loved how in Java, a method could handle an Exception and/or throw it. The method signature allows to put "throws MyException", so a good IDE/compiler would know that if you use said method somewhere in your code, you'd have to check for the Exception or declare your function to "throws" the Exception further. I'm unable to find something alike in Perl. A collegue of mine wrote a method which "dies" on incorrect input, but I forget to eval-if($@) it... offcourse the error was only discovered while a user was running the application. (offcourse I doubt if there is any existing IDE that could find these kind of things for Perl, but atleast perl -cw should be able to, no?)

    Read the article

  • Executing <script> elements inserted with .innerHTML

    - by phidah
    I've got a script that inserts some content into an element using innerHTML. The content could for example be: <script type="text/javascript">alert('test');</script> <strong>test</strong> Problem is that the code inside the <script> tag doesn't get executed. I googled it a bit but there were no apparent solutions. If I inserted the content using jQuery $(element).append(content);the script parts got eval'd before being injected into the DOM. Has anyone got a snippet of code that executes all the <script> elements? The jQuery code was a bit complex so I couldn't really figure out how it was done.

    Read the article

  • Accessing object property as string and setting its value

    - by ludicco
    Hello there, I have an object in csharp from the class Account each account have a owner, reference, etc. One way I can access an accounts properties is through accessors like account.Reference; but I would like to be able to access it using dynamic string selectors like: account["PropertyName"]; just like in javascript. so I would have account["Reference"] which would return the value...but I also would like to be able to sign a new value after that like: account["Reference"] = "124ds4EE2s"; I've noticed I can use DataBinder.Eval(account,"Reference") to get a property based on a string, but using this I can't sign a value to the property. Any idea on how I could do that? Thanks a lot

    Read the article

  • Is `eval`ing in a CPAN module without localizing $@ a bug?

    - by rassie
    I think I've encountered a bug in Params::Validate, but I'm not sure whether I identified the problematic code piece correctly. The code in question failed to pass exceptions up the chain (using Try::Tiny), so I started debugging and found out that a class used inside the try block has a destructor. This destructor calls object methods which use Params::Validate and looking into Validate.pm source I see an eval without $@ localization, i.e. the global $@ gets overwritten. Now I see two options: Params::Validate should always localize $@ and thus it's a bug that should be reported. The bug is in the class in question, because it shouldn't use Params::Validate in a destructor. Params::Validate can stay as it is now. Which one is it? How I should I handle this situation? PS: I think that CPAN modules should be rock-solid and neither break themselves nor their environment, hence the question title.

    Read the article

  • VB.NET logical expression evaluator

    - by Tim
    I need to test a logical expression held in a string to see if it evaluate to TRUE or FALSE.(the strig is built dynamically) For example the resulting string may contain "'dog'<'cat' OR (14 AND 4<6)". There are no variables in the string, it will logically evaluate. It will only contain simple operators = < < = <= and AND , OR and Open and Close Brackets, string constants and numbers. (converted to correct syntax && || etc.) I currently acheive this by creating a jscipt function and compiling it into a .dll. I then reference the .dll in my VB.NET project. class ExpressionEvaluator { function Evaluate(Expression : String) { return eval(Expression); } } Is there a simpler method using built in .NET functions or Lamdba expressions.

    Read the article

  • python dictionary conversion from string?

    - by shahjapan
    if I've string like "{ partner_name = test_partner}" OR " { partner_name : test_partner } its an example string will be very complex with several special characters included like =, [ , ] , { , } what will be the best way to convert it into a python object - so I can process it I tried with eval but it requires " ' " for string, but how can we add this special character \' before starting and ending of every word, I tried regular express re.findal('\w+') but it fails when my string contains ' _ ' or like characters as it will separate the string by ' _ ' Object of this question is my application needs, user friendly language as input - and I thought Json Dict will be good - but user is lazzy to put " ' " before and after of each string... then I thought for yaml but its also complex, if anybody can suggest better user friendly input which I use as python object - then please help me out.

    Read the article

  • is it possible to evaluate JavaScript code using XMLHttpRequest

    - by user1064717
    I'm trying to use this ajax request to call a file with some php which is working ok and some JavaScript which is not. any ideas? function showpart2(){ if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET","atuamae.org/parte2-encomendar.php",false); xmlhttp.send(null); } document.getElementById('part2').innerHTML = xmlhttp.responseText; eval(xmlhttp.responseText.getElementById('part2').innerHTML) setTimeout('showpart2()',15000); } showpart2(); </script>

    Read the article

  • How can I gzinflate and save the inflated data without running it? (Found what I think is a trojan o

    - by Rob
    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 its source. Any help?

    Read the article

  • How to use class_eval <<-"end_eval" in Ruby? Not parsing correctly

    - by viatropos
    I would like to define dynamic methods based on some options people give when instantiating it. So in their AR model, they'd do something like this: acts_as_something :class_name => "CustomClass" I'm trying to implement that like so: module MyModule def self.included(base) as = Config.class_name.underscore foreign_key = "#{as}_id" # 1 - class eval, throws these errors # ~/test-project/helpers/form.rb:45: syntax error, unexpected $undefined # @ ||= MyForm.new( # ^ # ~/test-project/helpers/form.rb:46: syntax error, unexpected ',' #~/test-project/helpers/form.rb:48: syntax error, unexpected ')', # expecting kEND from ~/test-project/helpers.rb:12:in `include' base.class_eval <<-"end_eval", __FILE__, __LINE__ attr_accessor :#{as} def #{as} @#{as} ||= MyForm.new( :id => self.#{foreign_key}, :title => self.title ) @#{as} end end_eval end end But it's throwing a bunch of errors I've printed in the comments. Am I using this incorrectly? What are some better ways I can define dynamic method names and dynamic names inside the method like this? I see people use this often instead of define_method (see these classes in resource_controller and couchrest toward the bottom). What I missing here? Thanks for the help

    Read the article

  • Can I have a shell alias evaluate a history substitution command?

    - by Brandon
    I'm trying to write an alias for cd !!:1, which takes the 2nd word of the previous command, and changes to the directory of that name. For instance, if I type rails new_project cd !!:1 the second line will cd into the "new_project" directory. Since !!:1 is awkward to type (even though it's short, it requires three SHIFTed keys, on opposite sides of of the keyboard, and then an unSHIFTed version of the key that was typed twice SHIFTed), I want to just type something like cd- but since the !!:1 is evaluated on the command line, I (OBVIOUSLY) can't just do alias cd-=!!:1 or I'd be saving an alias that contained "new_project" hard-coded into it. So I tried alias cd-='!!:1' The problem with this is that the !!:1 is NEVER evaluated, and I get a message that no directory named !!:1 exists. How can I make an alias where the history substitution is evaluated AT THE TIME I ISSUE THE ALIAS COMMAND, not when I define the alias, and not never? (I've tried this in both bash and zsh, and get the same results in both.)

    Read the article

  • How does this ruby custom accessor work

    - by ennuikiller
    So the method below in class_eval dynamically creates accessors for attributes defined at runtime. It can be used, for example, to create configuration objects with attributes read from a config file (and unknown until runtime). I understanding all of it except for the else branch. If I am correct the else branch returns the attribute value (val[0]) if there is one value passed in *val. However the way its written I would expect it to return an array (val) if there is more then one value passed in *var. In particular, if I have something like the following: value = 5 then from reading the code I would expect "#{@value}" to be [=,5]. However "#{@value}" returns 5 and not the array [=,5]. How is this possible? class Module def dsl_accessor(*symbols) symbols.each do |sym| class_eval %{ def #{sym}(*val) if val.empty? @#{sym} else @#{sym} = val.size == 1 ? val[0] : val end end } end end end

    Read the article

  • What does class_eval <<-"end_eval", __FILE__, __LINE__ mean in Ruby?

    - by viatropos
    I'm learning how to use class_eval in modules (I'm somewhat familiar with class_eval) and came across this helpful class in resource_controller. In there they have things like this: class_eval <<-"end_eval", __FILE__, __LINE__ def #{block_accessor}(*args, &block) unless args.empty? && block.nil? args.push block if block_given? @#{block_accessor} = [args].flatten end @#{block_accessor} end end_eval What does __FILE__ and __LINE__ do in that context? I know __FILE__ references the current file, but what does that whole thing do exactly? Don't really know how to search for that :).

    Read the article

  • javascript variable evaluation in function

    - by lamerzpua
    I trying to use simile widget for own need but I'm stuck on such problem. I have loop for (i=0;i<15;i++){ Timeline.loadXML(function_that_return_url(), function(xml, url) { eventSource[i].loadXML(xml, url); }); } This code is for Timeline.loadXML: Timeline.loadXML = function(url, f) { var fError = function(statusText, status, xmlhttp) { alert("Failed to load data xml from " + url + "\n" + statusText); }; var fDone = function(xmlhttp) { var xml = xmlhttp.responseXML; if (!xml.documentElement && xmlhttp.responseStream) { xml.load(xmlhttp.responseStream); } f(xml, url); }; SimileAjax.XmlHttp.get(url, fError, fDone);}; When I open the page - my function function(xml, url) { eventSource[i].loadXML(xml, url); }); is passed to loadXML method which use it inside as f(xml, url); Problem is that i variable is not parsed as number and I receive message that eventSource[...] is not declared. How I can evaluate i values before it will be posted as argument for the method LoadXML ?

    Read the article

  • Lua parser in python

    - by Joe Simpson
    Hi, I'm looking into using Lua in a web project. I can't seem to find any way of directly parsing in pure python and running Lua code in Python. Does anyone know how to do this? Joe

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >