diff chapter8/LongLines.scala @ 0:b316eec6fa7a draft default tip

add sample files
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 08 Jan 2013 16:41:46 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/chapter8/LongLines.scala	Tue Jan 08 16:41:46 2013 +0900
@@ -0,0 +1,21 @@
+import scala.io.Source
+object LongLines {
+    def processFile(filename: String, width: Int ) {
+	val source = Source.fromFile(filename)
+	for (line <- source.getLines)
+	    processLine(filename, width, line)
+    }
+    private def processLine(filename: String, width: Int, line: String) {
+	if (line.length > width)
+	    println(filename + ": "+ line.trim)
+    }
+}
+
+object FindLongLines {
+    def main(args: Array[String]) {
+	val width = args(0).toInt
+	for (arg <- args.drop(1))
+		LongLines.processFile(arg, width)
+    }
+}
+