syntax

How do I use a block as an 'or' clause instead of a simple die?

I want to check the results of an operation in the Net::FTP Perl module rather than die. Typically you would do: $ftp->put($my_file) or die "Couldn't upload file"; But I want to do something else instead of just dying in this script so I tried: $ftp->put($my_file) or { log("Couldn't upload $my_file"); return(-1); }...

(Mis)Understanding Smalltalk and TDD

I'm trying to learn Smalltalk by doing, so I'm getting a grip on the syntax and style by buiding a simple "Matrix" class. First of all, I'd be grateful if linked to a good Smalltak tutorial (although this is totally optional), preferably one that doesn't involve using the GUIs (I'd rather type my .sts than fish around the hierarchy expl...

Powershell writing tabs to a file

I need to echo a series of elements of an array in PS but provide various delimiters between the elements, so Im using; Add-Content -Path $tempInputDir\testoutput.log -value ($($fields[0]) + " "+ $($fields[1]) + " " + $($fields[2]) + " " + $($fields[3])+ " "+ $($fields[15]) + " " + $($fields[17])) } So I need to be able to add...

What is the question mark's significance in mysql?

I am dissecting some code and came across this, $sql = 'SELECT page.*, author.name AS author, updator.name AS updator ' . 'FROM '.TABLE_PREFIX.'page AS page ' . 'LEFT JOIN '.TABLE_PREFIX.'user AS author ON author.id = page.created_by_id ' . 'LEFT JOIN '.TABLE_PREFIX.'user AS updator ON updator.id = page.updated_by_id ' ...

Comment out a python code block

Is there any mechanism to comment out large blocks of Python code? Right now the only ways I can see of commenting out code are to either start every line with a #, or to enclose the code in """ (triple quotes), except that actually makes it show up in various doc tools. Edit--After reading the answers (and referring to the "duplicate")...

How to create a new scope using let in F#?

I am trying to initialize an XmlDocument in F#, without polluting the global namespace - my only functional background comes from LISP, where one can create a new scope using "let". I came up with this: let doc = let reader = new XmlTextReader("url") let doc = new XmlDocument() doc.Load(reader) doc I was rather surpri...

What is the correct syntax to represent subobjects in JSON?

I have a simple object that is deserialized from JSON into a server-side object. JSON: { name : 'ObjectName', host : 'http://localhost', ImagesPath : '/Images/' } On the server side, the above JSON code gets deserialized into this C# object via System.Web.Script.Serialization.JavaScriptSeriali...

Powershell expensive parsing

Hi Guys, Heres a little segment from a script Im writing; Get-Content $tempDir\$todaysLog | Where-Object { $_ -match "" } | ForEach-Object -Process { $fields = [regex]::split($_,'@|\s+') Add-Content -Path $importSource2\$todaysLog -value ($($fields[0]) + "`t" + $($fields[1]) + "`t" + $($fields[2]) + " " + $($fields[3])+ "`...

Method Syntax in Objective C

Can someone explain this method declaration syntax for me? In this function, the number of rows of a UIPickerView (slot machine UI on the iPhone) is being returned. From my understanding, the Method is called 'pickerView', and returns an NSInteger. It passes in a pointer to the UIPickerview called 'pickerView' ... first, why is th...

Are curly brackets used in Lua?

If curly brackets ('{' and '}') are used in Lua, what are they used for? ...

Can C++ method names be qualified by the class name, in the header?

Hi. Simple question, is this valid C++: class Foo { void Foo::doSomething(); }; The point of the question: is that repeated use of the class name and double colon before the method name valid inside the class declaration? I'm having issues compiling code that does this using g++ 4.2.3. I would love to see a reference to somethin...

Syntax Highlighting

I'm looking for a general purpose syntax highling library, to output to html. It's for use within a ruby app, so a ruby library would be good, but an excellent utility which can be piped in and out of would do Also needs to guess the appropriate language to highlightsy by itself ...

What's the Scala syntax for a function taking any subtype of Ordered[A]?

I want to write a function that works on any Scala type with a total ordering (i.e. I can use '<' on it). What's the syntax for that? The best I've come up with is def lessThan[T <: Ordered[T]](x: T, Y: T) = x < y That doesn't work, though, when I try using it from the REPL: scala> lessThan(1, 2) <console>:8: error: inferred type a...

What does a C# for loop do when all the expressions are missing. eg for(;;) {}

I can only assume it's an infinite loop. Can I leave out any of the three expressions in a for loop? Is there a default for each when omitted? ...

Why do I get a jQuery syntax error with .post and hide("slide")?

After I do the .post thing, I want to hide the first div with a left slide, then show the second with a right slide. My right-slide was working fine and then I went and tried to put in the left slide and I broke it all. if(hasError == false) { $.post("/process-email-signups",{email_address: email_addressVal}, function(data){ ...

Finding Uploads in Parameters on Submit in Rails

I'm trying to figure out which of these parameters contains an uploaded file. This code works params[:upload].each do | uploaded_image | if (uploaded_image[1] != "") # do something with uploaded_image[1]; end end but my way of moving through the parameters (with the [1], for instance) seems wrong. What's the right wa...

(*this)[i] ?

I overloaded the [] operator in my class. Is there a nicer way to call this function from within my class other than (*this)[i]? ...

What's the feature in Ruby that allows "p *1..10" to print out the numbers 1-10?

require 'pp' p *1..10 This prints out 1-10. Why is this so concise? And what else can you do with it? ...

What is this Objective-C syntax, ellipse style dot notation? "..."

Hi all, I noticed this in Joe Hewitt's source for Three20 and I've never seen this particular syntax in Objective-C before. Not even sure how to reference it in an appropriate Google search. From TTTableViewDataSource: + (TTSectionedDataSource*)dataSourceWithObjects:(id)object,... { The "..." is what's throwing me off here. I'm assu...

Need a simple explanation of the inject method

[1, 2, 3, 4].inject(0) { |result, element| result + element } # => 10 I'm looking at this code but my brain is not registering how the number 10 can become the result. Would someone mind explaining what's happening here? ...