[Scala] 命令行编译运行

背景

最近工作中需要用scala开发一个简单的脚本,希望做到每次只输入入参。如果进入scala RELP交互式界面,则需要每次都输入所有代码。

  1 // ProductCategoryAppid.scala
  2 object ProductCategoryAppid {
  3 	def main(args:Array[String]): Unit = {    
  4     	val str = args(0) // input a
  5     	val tmp = str.split(",").map(x=>x.split(":")(0))
  6     	val res = tmp.map(x=>"\"".concat(x).concat("\""))
  7     	println(res.mkString(","))
  8     }
  9 }

方法1

$ scala ProductCategoryAppid.scala "1426584:3.0,2801778:3.0"
$ "1426584","2801778"

方法2

$ scalac ProductCategoryAppid.scala

可以看到,编译之后,会生成如下若干文件

ProductCategoryAppid$$anonfun$1.class
ProductCategoryAppid$$anonfun$2.class
ProductCategoryAppid$.class
ProductCategoryAppid.class
ProductCategoryAppid.scala

然后

$ scala ProductCategoryAppid "1426584:3.0,2801778:3.0"
$ "1426584","2801778"

总结

在Linux环境中直接运行scala,可以直接scala xx.scala args。也可以先scalac xx.scala,然后再scala xx args。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值