星期日, 5月 30, 2010

新版 ydict ! update: 2013/07/10


最近 yahoo 的字典改版了, 害 4$ 改寫的 ydict 不能用了, 只好重新寫 parser ...
這邊是我重寫的 ydict, 配色和版面都參考之前的 ydict, 但是 parser 整個重新寫了, 以 MIT licence 釋出:

最新的版本可到這邊下載:
https://github.com/freehaha/ydict/releases


歡迎自由抓取修改, 但是使用後果自行負責!
-------------------------------
6/23 更新:
yahoo 字典的音標位置有點變, 造成音標抓不到, 改過來了
-------------------------------
6/27 更新:
改了一下切割英/中 example 的 regexp, 稍微改善一點排版

由於新版的 yahoo 字典的例句中英沒有明顯的分隔, 目前我只能由找到的第一個非英文字來分割中英文,還是有點瑕疵不過還算堪用啦 XD

-------------------------------
2012/12/07 更新
前幾天有發現 ydict 不能用了,但沒有特別注意,今天學長說不能用了我才發現還有人在用 ydict, 決定來改一改. 這個版本除了原本的功能還加上了變化型和同義字。可能還有些 bugs, 歡迎大家回報(雖然我可能不會馬上改就是了^^|||)。
-------------------------------
2013/04/02 更新
修正部份字詞 (colour, children) 會漏抓解釋的問題。
-------------------------------
2013/07/10
想說怎麼都查不到字, 結果是 yahoo 字典又改版了! 已更新.
另外開了 github 的 repo: https://github.com/freehaha/ydict, 歡迎任何 pull request.
-------------------------------
2013/07/25
yahoo 又改回之前的版本, 請到上面 github 的連結去下載最新的版本(其實是 20130402 的 版本, 上面前兩個連結將不會繼續更新, 以後請到 github 下載. 有問題的話也可以在那邊發 issue 給我.
-------------------------------
2013/08/14
後續就不在這邊更新了, 可以到以上 github 連結看 README 跟 release. 有問題還是歡迎在這邊留言, 或是到 github 發 issue ticket.

星期六, 5月 01, 2010

perl 的 'exists' in array, hash references

今天在寫 perl 發現奇怪的 bug,Glib::Timeout 收到 unhandled exception 就停掉了,看了 error log,這我明明就處裡的好好的阿!
簡化過的問題如下:
#!/usr/bin/perl
use strict;
                                                                                                                                                              
sub retundef {
    #something wrong
    return undef;
}  

my $ret = &retundef();
if(exists $ret->{dummy}) {
    print "gasp!?\n";
}  
exit 1 unless $ret;
if(@{$ret->{list}}) {
    local $, = ", ";
    print @{$ret->{list}};

}
exit 0;
看起來很簡單的 code 卻暗藏玄機,居然 return 0; why??? 我左看右看,才想到可能是 exists 的問題。perldoc 的 exists 是這樣寫的:

Although the mostly deeply nested array or hash will not spring into existence just because its existence was tested, any intervening ones will. .... This happens anywhere the arrow operator is used...
原來在 $ret->{dummy} 以後, $ret 就自動變成 hash reference 了,雖然 $ret->{dummy} 還是不存在,但是卻改變了 $ret。
------------
不得不說,喜歡 C 不是沒有原因的... perl 寫起來方便(光是 hash table 就大勝) 但是對於一些 reference,包括 GC 的處理上的確不太透明;看來我要學得東西還很多...