[問題] 關於syntax error 找不到bug!!

看板Perl作者 (= =)時間16年前 (2009/05/17 11:19), 編輯推噓2(200)
留言2則, 1人參與, 最新討論串1/1
我要寫一個判斷標題是屬於哪一個區域的小程式 首先從我原有的檔案內讀出資料 並擷取title的部分 然後用正規表示法去判斷是哪個區域 原本用if的寫法可以 可是換成given when 以後 就變成出現一個syntax錯誤的訊息 可是我怎麼看都看不出來 請大大指點一下 以下是程式碼!! -------------------------------------------------- #! /usr/bin/perl use warnings; open(FHD,"test.txt")or die; while($line=<FHD>) { my ($no,$date,$type,$title,$link)=split(/\,/,$line); my $what=''; given($title){ when(not $title=~ /台北|北市|北縣/){$what .='tpi';continue} when(not $title=~ /台中|中部/) {$what .='taichung';continue} when(not $title=~ /南投|埔里/) {$what .='nanto';continue} when(not $title=~ /雲林/) {$what .='winlin';continue} when(not $title=~ /台南|南縣|南市/){$what .='tainan';continue} when(not $title=~ /高雄/) {$what .='kao';continue} when(not $title=~ /屏東|墾丁|恆春/){$what .='pintong'} } say "$what"; } -------------------------------------------------- 謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.127.200.211

05/17 15:31, , 1F
你這個應該是程式最前面少了加上 use feature ":5.10";
05/17 15:31, 1F
先謝謝L大大 ,不過新增後 反而出現了 "Can't locate feature.pm in @INC" 是不是代表沒有安裝啊!!?? ※ 編輯: satisf 來自: 140.127.220.24 (05/17 16:11)

05/17 16:59, , 2F
你有裝 Perl 5.10 嗎 @@" 理論上應該要有才是
05/17 16:59, 2F
文章代碼(AID): #1A3u8ogO (Perl)
文章代碼(AID): #1A3u8ogO (Perl)