Recently in Perl Category

July 25, 2010

中文姓名產生器

用 Perl, Ruby, Javascript 三種程式語言寫了中文姓名產生器。原始碼丟去 gist 上: http://gist.github.com/476669 ,用來生假資料時意外好用。姓氏與名字的資料分別是取自於 chtsai [1], [2]。


July 13, 2010

解題

在 Perl 社群的 Blog 上看到 這個問題:

Consider a word (well, invented one): noogoo. Now, consider you want to do all possible combinations substituting oo with aa, that is, generate naagoo and noogaa.

也就是說,寫個函式,讓它吃三個字串輸入: s, x, y。並使其傳回一集合,內容是:將 s 中各處出現的 x 代換為 y 的組合。有字串代換,有排列組合,是個有意思的題目。

Continue reading 解題.

June 24, 2010

Perl 5.13.2 的 package 區塊語法

Perl 5.13.2 中有一項很值得一提的變動是加上 package 區塊的語法。

Continue reading Perl 5.13.2 的 package 區塊語法.

June 21, 2010

Define method on objects

This idea has been brewing in my head ever since I blogged about Mocking, and I finally decide to name it: Object::Method.

Continue reading Define method on objects.

June 17, 2010

Deleted CGI-Vote dist from CPAN

CGI::Vote was one of my early modules way back. That module is now useless and it’s easy to be replaced with a few lines of Dancer, Catalyst, or Jifty code. I finally decided to remove it from CPAN. If anyone still want it for any reason, please find it in my backpan dir . However, whatever reason you have I really recommend you to MOVE ON to new Plack-based web toolchains.

May 23, 2010

httpd-here: 隨處開設的網頁伺服器

還記得 IO::All 的 A Tiny Web Server 嗎:

perl -MIO::All -e 'io(":8080")->fork->accept->(sub { $_[0] < io(-x $1 ? "./$1 |" : $1) if /^GET \/(.*) / })'
Continue reading httpd-here: 隨處開設的網頁伺服器.

May 20, 2010

perlbrew PATH in Emacs.app

Emacs.app on Mac is not launched with the same $PATH set from bashrc/cshrc, which means perlbrew cannot work without some special treatments. One common problem is that cperl-perldoc will not be able to find the module document correctly. If you’re experiencing it, keep reading.

Continue reading perlbrew PATH in Emacs.app.

May 14, 2010

perlbrew problem with Net::DNS

If you're on Mac, using perlbrew and try to install Net::DNS, you might see it fail with this error message:

ld: in netdns.a, archive has no table of contents
collect2: ld returned 1 exit status
make: *** [blib/arch/auto/Net/DNS/DNS.bundle] Error 1

I'm not sure what causes it yet but I'm guessing that I need to play with some LD_LIBRARY_* variables since perlbrew installs perl to $HOME. Before it's fixed, heres' an work-around:

ranlib netdns.a

Execute that command after you see the ld error. After that, proceed the installation with:

make
make test && make install

You should see the tests are passing just fine.

May 7, 2010

Install all used modules at once

Ever since perlbrew was made useful, switching among different versions of perl makes it painful to re-install the required modules over and over. That's why I wrote this module-used program to rescue me.

The usage of module-used is heavily inspired by tokuhirum++'s cpan-outdated program:

cd /to/my/awesome-project
module-used

That gives you a list of module names which are found to be used in some source files under current directory. It can then be piped to xargs cpan -i to perform bulk module installation:

module-used | xargs cpan -i
module-used | xargs cpanm

Although cpanm --installdeps is doing basically the same thing here, this program is also helpful for module authors to get a list of names for their Makefile.PL or Build.PL, which might not be there in the first place if the current project is not planed to be uploaded to CPAN.

The module-used program itself uses Module::ExtractUse and List::MoreUtils , install them first, and the the program should be ready to run.

April 27, 2010

OSDC / RubyConf TW 2010 複習

結論: 今年的場地真是太高級了,以後場地沒有電源要怎麼辨啊...

在蛙咖啡的黑客鬆。先完成了 perlbrew 0.05 版。支援從 git 的 checkout 去編出一支新 perl。所以已經有用 git 取出 perl 程式的人就不必再花時間下載 perl 的 tarball 了。

然後再跟 Kawasaki-san 一起將他的 3D 投影片改成用 CSS3 的做法 (使用半透明的 color 與 text-shadow),並且製做成 bookmarklet。不必用愚人節版的 Google Chrome,開任何網站都可以變 3D !請參考 3d-bookmarklet.html。測試 3D 效果實在是令人頭暈目眩。在 3D 電視熱賣前,眼科診所的生意可能都會很好。

充份試用了 obra 的 iPad。

RubyConf 參加了半部,認識了一些 Takahashi-san 之外的日本 ruby 玩家。不過果然現在玩到 Ruby on Rails 的人都還是在談論現實面的話題 (要靠什麼賺錢)。

不過,如果只將自身能力侷限在一種語言當中,而窄化思路,那就太可惜了。

Less is more.

More is more.