Jon Aquino's Mental Garden

Engineering beautiful software jon aquino labs | personal blog

Friday, August 14, 2009

First Scala Program

One of my co-workers is big into the programming language Scala, and has inspired me to take a look. I’m slowly making my way through the free online book Programming Scala.

Here’s my first Scala program. It doesn’t do anything particularly Scala-ish—it just reads from stdin, sticking four spaces in front of every line that does not begin with “HTTP Method”, “Endpoint”, “Elapsed Seconds”, and a few other strings. So it’s a little formatting utility that’s useful at work.

var line = Console.readLine()
while(line != null) {
if (! line.matches("(HTTP Method|Endpoint|Elapsed Seconds|Request Headers|Response Code|Response Headers|Response Body).*")) { print(" ") }
println(line)
line = Console.readLine()
}


A cool thing is that my text editor jEdit lets me apply this script to the current buffer:

jEdit Text Filter plugin

Also note that jEdit lets you customize its toolbar with icons of unlimited size :-)

0 Comments:

Post a Comment

<< Home