syntax

Is there a compact Perl operation to slice alternate elements from an array?

If I have an array myarray in Python, I can use the slice notation myarray[0::2] to select only the even-indexed elements. For example: >>> ar = [ "zero", "one", "two", "three", "four", "five", "six" ] >>> ar [ 0 : : 2 ] ['zero', 'two', 'four', 'six'] Is there a similar facility in Perl? Thanks. ...

How to select all leaf nodes using XPath expression?

I believe it's possible but couldn't figure out the syntax. Something like this: xmlNode.SelectNodes("//*[count(child::*) <= 1]") but this is not correct. ...

Function declaration in python to have a readable and clean code?

Is it possible to declare functions in python and define them later or in a separate file? I have some code like: class tata: def method1(self): def func1(): # This local function will be only used in method1, so there is no use to # define it outside. # Some code for func1. # Some code for m...

How to resolve shift reduce conflicts in my grammar?

I'm writing a compiler from (reduced) Pascal into ARM asm. I'm at the second step of the process - after writing lexical analyzer now I'm working on syntax analysis with java cup. I have written my grammar, but got 5 S/R conflicts, which are all very similar. Example: Warning : *** Shift/Reduce conflict found in state #150 between a...

Is there a better way to use &mdash for multi-browsers?

Is there a better way to make the &mdash ...

What does the following colon (:) mean in MATLAB syntax?

a = imread('autumn.tif'); a = double(a); [row col dim] = size(a); red = a(:, :, 1); green = a(:, :, 2); blue = a(:, :, 3); What does the colon : in the last three lines mean? (The above snippet is from "Image Processing" by Dhananjay Theckedath.) ...

Problem select specific column name using sql statement

I found problem when trying to retrieve specific name column that using syntax/statement/command using sql. Example I have table 'dcparam' with name some column 'SELECT', 'INSERT', 'UPDATE' in database sqlserver. Then I trying to select using query: SELECT SELECT,INSERT,UPDATE FROM dcparam Well it could be solve using "*" in select, ...

unexplained syntax error defining threadpool inside class definition

I have the following class definition and for some reason I cannot define the threadpool inside the class definition itself. It says: syntax error: identifier 'numberofpoolthreads' I tried directly defining it in the class, but it gives me same syntax error, does anyone know why this is? #include "stdafx.h" #include <boost/threadpool....

What is this second new?

What is the second line? (Seen while answering another question.) int * x = new int [1] ; int * y = new (x) int; After the second line x and y have the same value (point to a same place). What's the difference between y = x and the second line? Is it like a constructor or something? ...

Google Go : declare / initialize

I'm currently playing with Google Go. There's a lot of ways to declare and/or initialize variables. Can someone explains pros/cons of each way (samples, as far as i know, below) : var strArr0 *[10]string = new([10]string) var strArr1 = new([10]string) var strArr2 = make([]string,10) var strArr3 [10]string strArr4...

C++ multicharacter literal

I didn't know that C and C++ allow multicharacter literal: not 'c' (of type int in C and char in C++), but 'tralivali' (of type int!) enum { ActionLeft = 'left', ActionRight = 'right', ActionForward = 'forward', ActionBackward = 'backward' }; Standard says: C99 6.4.4.4p10: "The value of an integer character const...

Why isn't "0f" treated as a floating point literal in C++?

Why isn't 0f treated as a floating point literal in C++? #include <iostream> using namespace std; int main(){ cout << 0f << endl; return 0; } Compiling the above gives me C2509 (syntax error: 'bad suffix on number') using VS2008. ...

Is it possible to alias bean class names in Spring?

I have a string property which looks similar to the following example: <property name="mappingData"> <list> <bean class="com.company.product.longNamingStandard.migration.extractor.FieldMapping"> <property name="elementName" value="entitlement.user"/> <property name="mapping" value="DocUsers"/> </bea...

What's the meaning of '_' in python?

When reading source code of Django, I find some statements: class Field(object): """Base class for all field types""" __metaclass__ = LegacyConnection # Generic field type description, usually overriden by subclasses def _description(self): return _(u'Field of type: %(field_type)s') % { 'fiel...

Syntax for C# Array[] in C++/CLI

I have an interface defined in C# which has a method Array[] Foo(); I need to implement this interface in a class written in C++/CLI. i tried the following syntax array<array<Object^>^>^ Foo(); But i get an error stating my return type does not match the one in the interface. Does anyone know how to translate a C# Array[] to C++/CL...

I'm trying to write a function for postgresql to do some string manipulation...

The purpose of the function is to take a string and, if it contains parens, delete everything in the parens. Here's what I have: CREATE FUNCTION clearmethodparams(IN qname text) RETURNS text AS $BODY$ IF position($o$($o$ in qname) = 0 THEN return qname; ELSE return substring(qname from 0 for position($p$($p$ in qn...

YAML syntax validator?

I am having issues pulling from a YAML config file : `Fatal error: while parsing a block mapping; expected , but found BlockEntry . I recall being able to copy/paste my YAML contents into a website, and it giving me line-by-line syntax errors. Does anyone know of a linux package that will fix errors like this, or the website I am think...

C#; making a new delegate without declaring the method separately?

I'm able to compile code that includes this: OperationDelegate myOpDelegate; static OperatorDefinition[] definitions ={ new OperatorDefinition("+",2,3,true, new OperationDelegate(OperationAdd)), }; delegate double OperationDelegate(double[] args); static double OperationAdd(double[] args) { ...

Using try-catch block in a function

This really isn't an important question. I just wanted to know which method is more popular and whether there's some sort of a de facto standard. This, function foobar { int retVal = 0; try { retVal+=100; } catch { //error handling code } return retVal; } Or this? function foobar { ...

Get Insert Statement for existing row in MySQL

Using MySQL I can run the query: SHOW CREATE TABLE MyTable; And it will return the create table statement for the specificed table. This is useful if you have a table already created, and want to create the same table on another database. Is it possible to get the insert statement for an already existing row, or set of rows? Some ...