Ruby練習
ちょっとしたスクリプトを書きました。 - だらだらやるよ。
ちゃんと勉強したいなと思いつつ、まだclassとか使ったことない。
# rows.rb # usage: rows.rb ./ \.rb$ $t = 0 def rec (d) Dir.glob(d+'*'){|f| if File.directory?(f) rec f+'/' elsif f.match($*[1]) c=0 open(f){|s| c+=1 while s.gets; printf "%8d : %s\n",c,f } $t+=c end } end rec $*[0].sub('/?$','/') puts '-'*40 printf "%8d : total",$t
潜らない&トータル計らない1liner (引数はwildcard)
$*.map{|f|c=0;open(f){|s|c+=1 while s.gets};printf "%8d : %s",c,f}
(defun rows (path ext) (let ((total 0)) (labels ((rec (p e) (dolist (f (directory p :directory-only t)) (rec #1=(merge-pathnames f p) e)) (dolist (f (directory p :wild ext)) (let ((c 0)) (with-open-file (s #1#) (while (read-line s nil) (incf c))) (incf total c) (format t "~8D : ~A~%" c #1#))))) (rec path ext)) (format t "~8D : total" total))) (rows "~/site-lisp" "*.l")