自作のrubyスクリプトが動かない
二つ下のディレクトリにあるファイルを先頭の一行だけ取ってきてリストアップしたいんだけど、何か変。
list = ""
prbdir = "./problems/v" + vol
File.foreach( prbdir + "/index" ) do |id|
prbfn = prbdir + "/p" + id.to_s.untaint
prbfh = open( prbfn, "r" )
begin
list += cgi.li{ prbfh.readlines[0] }
ensure
prbfh.close
end
end
これは problems.rb の一部ですが、実行したら以下のエラー。ちなみに 44 行目は上で抜粋したコードのちょうど真ん中にある open() を呼んでいる行。
./problems.rb:44:in `initialize': No such file or directory - ./problems/v0/p0 (Errno::ENOENT)
そのファイルはあるのになぁ…。汚染度かと思って untaint してるけど違うみたいだし。
追記。File.foreach で行をとってくるので id は末尾に改行( $ )が入っていたのでした。 id.rstrip で除去することで解決。
About this entry
You’re currently reading “自作のrubyスクリプトが動かない,” an entry on 数奇な因子
- Published:
- 日曜日, 7月 16th, 2006 at 16:34:28
- Author:
- line
- Category:
- programming
Comments are closed
Comments are currently closed on this entry.