Scala 範例程式 - 比對 (Match)

原始程式:Match.scala

/** Basic command line parsing. */
object Match {
  var verbose = false

  def main(args: Array[String]) {
    for (a <- args) a match {
      case "-h" | "-help"    =>
        println("Usage: scala Main [-help|-verbose]")
      case "-v" | "-verbose" =>
        verbose = true
      case x =>
        println("Unknown option: '" + x + "'")
    }
    if (verbose)
      println("How are you today?")
  }
}

執行結果:

D:\Scala\code>scalac Match.scala

D:\Scala\code>scala Match -v -help
Usage: scala Main [-help|-verbose]
How are you today?
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License