[問題] =~
大家好
我碰到的問題是下列程式碼執行的結果:
#encoding : big5
pattern = Regexp.new(ARGV[0])
filename = ARGV[1]
file = open(filename)
while text =file.gets do
if pattern =~ text
print text
end
end
file.close
這是我照書上打的程式
但是當我執行時輸入: ruby 檔名.rb xxx yyy.txt
之後就會顯示出錯誤訊息:
grep.rb:10:in `=~': invalid byte sequence in Big5 (ArgumentError)
from grep.rb:10:in `<main>'
為什麼會這樣?我照書上的寫,同一個目錄下也真的有yyy.txt
找不到錯誤QQ
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.170.224.200
※ 編輯: fbukevin 來自: 118.170.224.200 (07/19 15:43)
→
07/19 15:47, , 1F
07/19 15:47, 1F
→
07/19 16:04, , 2F
07/19 16:04, 2F
→
07/19 16:05, , 3F
07/19 16:05, 3F
→
07/19 18:53, , 4F
07/19 18:53, 4F
推
07/19 21:16, , 5F
07/19 21:16, 5F
推
07/20 01:14, , 6F
07/20 01:14, 6F
推
07/20 09:15, , 7F
07/20 09:15, 7F
推
07/20 09:28, , 8F
07/20 09:28, 8F
→
07/20 09:32, , 9F
07/20 09:32, 9F
→
07/20 09:33, , 10F
07/20 09:33, 10F
→
07/20 09:33, , 11F
07/20 09:33, 11F
推
08/19 23:52, , 12F
08/19 23:52, 12F
→
08/19 23:53, , 13F
08/19 23:53, 13F