• scala 命令台参数解析


    sliding :

    
    object SlidingParser extends App{
    var name = ""
    var port = 0
    var ip = ""
    args.sliding(2, 2).toList.collect {
    case Array("-a", argIP: String) => ip = argIP
    case Array("-b", argPort: String) => port = argPort.toInt
    case Array("-c", argName: String) => name = argName
    }
    println(name)
    println(port)
    println(ip)
    }
    
    

    Pattern matching :

    
    object Parser {
      val usage =
        """
        Usage: spark-submit --master=yarn xx.jar [-h] [-p] <inputCsvPath> [-o] <outputLogPath> [-f] <testFuncName>
      """
      type OptionMap = Map[Symbol, String]
    
      def nextOption(map: OptionMap, list: List[String]): OptionMap = {
        list match {
          case Nil => map
          case "-h" :: other =>
            nextOption(map ++ Map('help -> usage), other)
          case "-p" :: value :: tail =>
            nextOption(map ++ Map('inputCsvPath -> value.toString), tail)
          case "-o" :: value :: tail =>
            nextOption(map ++ Map('outputLogPath -> value.toString), tail)
          case "-f" :: value :: tail =>
            nextOption(map ++ Map('funcName -> value.toString), tail)
          case "-t" :: value :: tail =>
            nextOption(map ++ Map('perfTestTimes -> value.toString), tail)
          case "-s" :: tail =>
            nextOption(map ++ Map('showFlag -> true.toString), tail)
          case option :: tail =>
            nextOption(map, tail)
        }
      }
    }
    
  • 相关阅读:
    深度学习
    定义一个变长数组和常量引用参数
    深度神经网络tricks and tips
    PCA whitening
    反向传播
    激活函数
    C++中模板的使用
    数据结构 (二叉树)1
    C++中的函数指针和函数对象总结
    从头到尾彻底解析Hash表算法
  • 原文地址:https://www.cnblogs.com/mangoczp/p/12803778.html
Copyright © 2020-2023  润新知