25. export JAVACMD=$HOME/local/bin/java
function scall () {
local f
while getopts 'e:B:E:' opt; do
case $opt in
B) B=$OPTARG;;
E) E=$OPTARG;;
e) f=$OPTARG;;
esac
done
shift $((OPTIND - 1))
if [[ x"$f" == x"" ]]; then
f='println'
fi
scala -e "import scala.io._;$B;
(if(args.length>0)args.map(arg=>Source.fromFile(arg,
"UTF-8"))else
Array(Source.stdin)).foreach(s=>s.getLines.foreach($f));$E" "$@"
}
26. #compdef scall
function _scall () {
_arguments :
'-h[Show message and exit]'
'-e[Specify expression to run with each line]:Expression'
'-B[Specify expression to run on begin of
program]:Expression'
'-E[Specify expression to run on end of program]:Expression'
'*:argument:_files'
}
29. $ time (scall ~/.zshrc > /dev/null)
(; scall ~/.zshrc > /dev/null; )
1.76s user 0.17s system 42% cpu 4.536 total
$ time (cat ~/.zshrc > /dev/null)
(; cat ~/.zshrc > /dev/null; )
0.00s user 0.00s system 61% cpu 0.004 total
$ time (perl -pe1 ~/.zshrc > /dev/null)
(; perl -pe1 ~/.zshrc > /dev/null; )
0.00s user 0.00s system 52% cpu 0.008 total
34. #
$ time (scall ~/.zshrc > /dev/null)
(; scala-2.8 -deprecation -cp com.myexample.Scall ~/.zshrc > /
dev/null; )
13.35s user 0.75s system 72% cpu 19.502 total
$ time (cat ~/.zshrc > /dev/null)
(; cat ~/.zshrc > /dev/null; )
0.00s user 0.00s system 61% cpu 0.004 total
$ time (perl -pe1 ~/.zshrc > /dev/null)
(; perl -pe1 ~/.zshrc > /dev/null; )
0.00s user 0.00s system 52% cpu 0.008 total