Scalaに投稿されたコード一覧
val regex = "([0-9]+.[0-9]+.[0-9]+.[0-9]+).*([0-3][0-9].[A-Z][a-z][a-z].20[0-1][0-9]:[0-2][0-9]:[0-5][0-9]:[0-5][0-9]).*".r; scala.io.Source.fromFile("./access_log").getLines().foreach( x => { x match { case regex(ip,date) => {println(ip +" at " + date) } case _ => println("no match") }}
import java.text.{SimpleDateFormat => SDF} val sdf = new SDF("yyyy-MM-dd'T'HH:mm:ssZ") def convertInt(x: String) = x.toInt
scala> "1234567789".map( x => x ) res0: String = 1234567789 scala> "1234567789".map( x => Option(x) ) res1: scala.collection.immutable.IndexedSeq[Option[Char]] = Vector(Some(1), Some(2), Some(3), Some(4), Some(5), Some(6), Some(7), Some(7), Some(8), Some(9))
scala> def date(year:Int, month:Int, day:Int) = "%s/%02d/%02d" format(year, month, day) date: (year: Int,month: Int,day: Int)String scala> date(2011, 07, 18) res22: String = 2011/07/18
scala> def date(month:Int=10, day:Int) = "%s/%s" format (month, day) date: (month: Int,day: Int)String scala> date(30) <console>:7: error: not enough arguments for method date: (month: Int,day: Int)String.
scala> def log(msg:String, length:Int = msg.length) = "[%s] %s" format(length, msg) <console>:5: error: not found: value msg def log(msg:String, length:Int = msg.length) = "[%s] %s" format(length, msg) ^