background preloader

Groovy

Facebook Twitter

Grails Tutorial - Grails, Rails, Groovy, Roo, Django, Ruby on Rails, Ruby. Groovy e seus mutantes: terceira parte do Guia Groovy/Grails em vídeo « /dev/Kico. CSV parser with groovy categories : Groovy Almanac. This shows how categories in groovy can be used to create a simple csv parser.

CSV parser with groovy categories : Groovy Almanac

To parse a csv file with the following content:A1,B1,C1 A2,B2,C2 A3,B3,C3 A4,B4,C4 A5,B5,C5 The following example can be used. The CSVParser has all the logic. class CSVParser { static def parseCSV(file,closure) { def lineCount = 0 file.eachLine() { line -> def field = line.tokenize(",") lineCount++ closure(lineCount,field) } } } To call it you simply say <pre>parseCSV</pre> <p>:</p> class CSVParser { static def parseCSV(file,closure) { def lineCount = 0 file.eachLine() { line -> def field = line.tokenize(",") lineCount++ closure(lineCount,field) } } } To call it you simply say. Running. Groovy scripts are a number of statements and class declarations in a text file.

Running

Groovy scripts can be used similarly to other scripting languages. There are various ways of running Groovy scripts.