Mercurial > hg > Members > nobuyasu > scala
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b316eec6fa7a |
---|---|
1 import scala.io.Source | |
2 object LongLines { | |
3 def processFile(filename: String, width: Int ) { | |
4 val source = Source.fromFile(filename) | |
5 for (line <- source.getLines) | |
6 processLine(filename, width, line) | |
7 } | |
8 private def processLine(filename: String, width: Int, line: String) { | |
9 if (line.length > width) | |
10 println(filename + ": "+ line.trim) | |
11 } | |
12 } | |
13 | |
14 object FindLongLines { | |
15 def main(args: Array[String]) { | |
16 val width = args(0).toInt | |
17 for (arg <- args.drop(1)) | |
18 LongLines.processFile(arg, width) | |
19 } | |
20 } | |
21 |