Parallel::ForkManager

在 Perl 裡面如何把這種程式平行化? 假設每次 interation 是獨立的。

foreach $data (@all_data) {
    eat_cpu($data);
}

超簡單


use Parallel::ForkManager; # !!
$pm = new Parallel::ForkManager($MAX_PROCESSES);

foreach $data (@all_data) {
    $pid = $pm->start and next;
    eat_cpu($data);
    $pm->finish;
}

Baseball::Sabermetrics 0.03

Baseball::Sabermetrics 0.03 released XD

example/ws.pl(這也是我寫這個 module 的主要目的之一)距上一次的 release 前進了一大步,主要是跟 Debugger.bbs@ptt 合作 debug。最近事情比較少,看能不能把 Win Share 公式整個弄完,這樣就可以即時知道每個球員的 WS 了 :p

Baseball::Sabermetrics

之前為了統計自己玩 cpb2 (an old dos game) 的成績,也正巧遇到 ptt Sabermetrics 板上 Debugger 提到他手動抓 CPBL 官網的資料算 Win Shares (WS 的計算很複雜,需要的資料量很多),於是寫了 Baseball::Sabermetrics 這個 perl module。他的功能是提供一個簡單的 programming interface 去抓一個聯盟的統計數據,目前內建 CPB2 與 CPBL 兩個聯盟。前幾天已經 upload 到 CPAN 上了,有興趣可以到 http://search.cpan.org 找 Baseball::Sabermetrics :D

使用方法跟範列,請見 http://search.cpan.org。

目前還有不少想加強的東西,例如 CPBL 的支援目前只有當季成績,而沒有歷史成績;聯盟的支援太少,想看看能不能用 WWW::Baseball::NPB 來納入對 NPB 的支援;MLB.com 的介面已經做得很不錯,我不確定有沒有人會需要,就再看看囉。

BTW, 為了簡化介面,裡面用了一些噁心的技巧,例如 sub AUTOLOAD : lvalue,另外還有 lazy evaluation with cache :D

Perl: ref LVALUE

While I’m working on Sabermetrics.pm (which is for basebal statistics. It’ll be released soon) these days, I encountered some problem and refered to ‘perldoc -f ref’. It mentions about returning LVALUE’ without any other information.

And I just find this sample program:

http://www.farid-hajji.net/books/de/Hajji_Farid/pbv2/pw/ref-lvalue.pl.html

Quite ugly. It seems to work on built-in function. I can’t figure out how to use it with my own function :(

WWW::OpenSVN !!

Wow, wow, wow! WWW::OpenSVN on CPAN!!

perl blog

寫個 perl 語的 blog !?

cpanplus’s dependency.deb

我把 cpanplus depend 的 perl packages 全包成 deb 了。如果想裝這些 cpanplus 跟這些 packages,可以在 /etc/apt/sources.list 中加入

deb http://victor.csie.org/debian/ unstable cpanplus

並安裝 libcpanplus-perl-snapshot :)

順便讀了 Debian Policy Manual 中關於 Conflics, Provieds, Replaces 的部分 :)

scw, pugs commiter!

今天 scw 成了 pugs 的 commiter! 真是強啊!

我也趁這個機會來玩玩 Functional Language (選了 Haskell 來玩 :)
這真是有趣的語言。