Perl planet
October 27, 2008
在 irc 上頭有朋友問是否有自動編排程式碼的程式,答案是有的。若要寫 C 你可以使用 GNU 的 Indent ,寫 perl 則有 perltidy 。<br /><br />在 Ubuntu/Debian 皆有套件可直接安裝使用 GNU Indent。<br /><br /><code>$ sudo apt-get install indent</code><br />GNU Indent 預設為 GNU Style 若要調整程式碼風格,可以在 ~/.indent.pro 內設定。(請參見 man indent 或參考 <a href="http://www.math.utah.edu/docs/info/indent_toc.html">GNU Indent Manual</a> )<br /><br />GNU Indent 的使用方式為:<br /><br /><code>$ indent [filename]</code><br />這樣會顯示編排後的程式碼,若用<br /><br /><code>$ indent file1 > file2</code><br />則會在 file2 存入編排後的程式碼。<br /><br />如果你有使用 vim ,你也可以將 GNU Indent 與 vim 的 [==] 功能做結合 ( 請參見 :help [==] ),vim 內有有名的 gg=G 大絕招可以編排整個檔案,預設是用 vim 去編排的,若要使用外部程式編排,可以使用 set equalprg 功能,在 .vimrc 內設定:<br /><br /><code>set equalprg=/usr/bin/indent</code><br />則在 vim 內選取區域後可按下等號,則 vim 會將此區塊傳至外部程式,再將外部程式的輸出結果替換。<br /><br />另外透過 autocmd 可以搭配不同的檔案類型設定不同的 indent program。<br /><br />譬如說我常用 perltidy 那麼可設定<br /><br /><code>au Filetype perl :set equalprg=perltidy</code><br />我所使用的 .perltidyrc:<pre class="code">-l=78<br />-i=4<br />-ci=4<br />-se<br />-vt=2<br />-cti=0<br />-pt=1<br />-bt=1<br />-sbt=1<br />-bbt=1<br />-nsfs<br />-nolq<br />-wbb="% + - * / x != == >= <= =~ !~ < > | &amp; >= < = **= += *= &amp;= <<= &amp;&amp;= -= /= |= >>= ||= .= %= ^= x="</pre>以及 .indent.pro:<pre class="code">-br -nce<br />-cdb -sc<br />-bad<br />-i8<br />-ci4<br />-di8<br />-nbc<br />-bfda<br />-bls<br />-ip0<br />-hnl</pre></content>
by c9s at October 27, 2008 07:00 AM
October 07, 2007
早上熟悉一下 FreeBSD , 在上面裝 KDE<br /><br />接著讀了一些 perldoc ,下午練了兩個小時的琴<br />後來因為停電,所以去練了一個小時的吉他,就練練音階,古典教材之類的 ...<br />接著讀了一個小時多的 Aho Compiler.<br />一個小時的托福字彙。<br /><br />最後真的沒事情可幹了,天色又暗,沒辦法看書,所以睡覺 ....<br />睡起來還是停電,所以吃飯。<br />吃完飯就有電可以看新聞了。<br /><br />XD 晚上繼續讀 perldoc 。<br /><br />哎喲,我很想澄清,Perl 根本就沒有像外人所說那樣無法閱讀。事實是,多樣化的 Perl 比較容易讓人摸不著邊罷了,但是那樣的 code 其實是很少的。<br /><br />阿,真是讓人腦殘的一 PO。 XD</content>
by c9s at October 07, 2007 04:00 AM
September 29, 2007
其實早就可以在 Perl5 上使用 Perl6 的一些小甜頭了。<br /><br />你可以安裝 v6-alpha , type:<br /><br /><code>$ sudo cpan v6</code><br /><br />可以 perl6 的方式來撰寫之。<br /><pre class="pre"># file: hello_world.pl<br />use v6-alpha;<br />"hello, world".say;</pre>實作的部份只有一部分,並不完整。v6-alpha 是實驗性質的東西,不過基本上可以當玩具玩玩。<br /><br />注意, v6-alpha 並不相依於 pugs 或 parrot,其物件模型是以 Moose 為基礎。<br /><br />其他可參考:<br /><a href="http://search.cpan.org/%7Efglock/v6-0.020/lib/v6.pm">http://search.cpan.org/~fglock/v6-0.020/lib/v6.pm</a></content>
by c9s at September 29, 2007 07:00 AM
編了 Perl5.9.5 ,這是 Development Version ,Sourcecode 可在 <a href="http://www.cpan.org/src/README.html">CPAN</a> 上下載 ,See the <a href="http://use.perl.org/articles/07/07/09/0655239.shtml">Announcement</a> 。步驟可參考 INSTALL 以及 README 檔。<br /><br /><code>$ sh Configure<br />$ make<br />$ make install</code><br /><br />Configure 可加上參數 -d 以預設值編譯。可下<br /><br /><code>$ sh Configure -d -Dprefix=/usr -Dusedevel</code><br /><br />如此即可。不過得注意的是:<br /><blockquote>It may seem obvious, but Perl is useful only when users can easily<br />find it. It's often a good idea to have both /usr/bin/perl and<br />/usr/local/bin/perl be symlinks to the actual binary. Be especially<br />careful, <span style="font-weight: bold; font-style: italic;">however, not to overwrite a version of perl supplied by your </span><span style="font-weight: bold; font-style: italic;">vendor unless you are sure you know what you are doing.</span></blockquote>參考看看 Perl 5.9.5 有哪些新東西 ( <a href="http://search.cpan.org/%7Ergarcia/perl-5.9.5/pod/perl595delta.pod">perldelta - what is new for perl v5.9.5</a> ),</content>
by c9s at September 29, 2007 07:00 AM
September 28, 2007
<a href="http://search.cpan.org/%7Enwclark/perl-5.8.8/utils/perlcc.PL">Perlcc</a> 可協助你將 perl 的 source code 編譯成 binary , c 或者 bytecode ,於是嘗試用 perlcc 來編譯:<br /><br /><code>$ perlcc -o test test.pl</code><br /><br />將 test.pl 編譯,並輸出為 test。不過遇到的編譯錯誤:<pre>pccl0GI5.c: In function ‘perl_init_aaaa’:<br />pccl0GI5.c:15664: warning: this decimal constant is unsigned only in ISO C90<br />/usr/bin/ld: cannot find -lperl<br />collect2: ld returned 1 exit status</pre>其實只要裝一下 libperl-dev 就可以解決這個問題了。<br /><br />安裝 libperl-dev:<br /><br /><code>$ sudo apt-get install libperl-dev</code><br /><br />重新編譯即可。 :)<br /><br />將 source code 編譯為 Bytecode 則可輸入 :<br /><br /><code>$ perlcc -B -o foo foo.pl</code><br /><br />產生出來的 Bytecode 會像是這樣:<pre class="code">use ByteLoader 0.06;<br />PLBCi486-linux-gnu-thread-multi^@0.06^@^D^@^@^@^D^@^@^@^L Ya^A^@^@^@d^Me@^L h^^A^@<br />^@^@^@<br />^@^@^@A^A<br />^@^@^@^G^A ^D^C<84>^D^N^M^@^@^@Hello world<br />^@^V^A^L^@^@^@<^C^@^@^@=^M^@^@^@=^M^@^@^@=^N^@^@^@A^A^A ^@^@^@<^C^@^@^@=^K^@^@^@=^L^@^@^@A^@^A ^@^@^@8 ^@^@^@;^P^@<87> ^@^@^@<88>^L^@^@^@^@</pre>可參閱:<br />Perl 語言全面編譯: <a href="http://fanqiang.chinaunix.net/a4/b3/20010419/150346_b.html">1</a>,<a href="http://fanqiang.chinaunix.net/a4/b3/20010419/150532_b.html">2</a>,<a href="http://fanqiang.chinaunix.net/a4/b3/20010419/150906_b.html">3</a><br /><br />PS. 對了,Programming Perl 3/e 上編譯 bytecode 是寫 -b ,不過正確的應該是 -B。</content>
by c9s at September 28, 2007 05:00 PM
September 25, 2007
剛剛有提到 Moose ,其實挺不錯,可以提供 Perl5 上一個良好的物件導向。<br /><br />不過基本上對 Perl5 的 Developer 比較像是種折磨。因為雖然 Moose.pm 在語法上類似於 Perl6 的寫法,但是有些小細節仍是不太一樣的 (<a href="http://pugs.blogs.com/talks/boston-deploying-perl6.pdf">可參考 Audreyt 的 Slide</a>)。看 Slide 看到這,我就覺得這會是個很頭痛的地方,因為當 Perl6 出來之後,你還得再習慣 Perl6 的 syntax,萬一你把小細節搞錯,出 Bug 的狀況反而更多...<br /><br />沒辦法,要從 Perl5 切到 Perl6 還得過一個尷尬的過渡期...<br /><br />不過,我認為 Perl6 已經超越了 Scripting Language 了!因為基本上他不僅吸收了 Haskell , Ruby , Python 等等許多語言的特色,還提供了多種的後端輸出。<br /><br />所以為了 Perl6 強大的功能 .... (忍痛 XDDDD)<br /><br />繼續寫 Perl 吧 XD</content>
by c9s at September 25, 2007 06:00 PM
如果要在 Perl 5 上寫 OO 的話,就用 <a href="http://search.cpan.org/%7Estevan/Moose-0.25/lib/Moose.pm">Moose.pm</a> 吧!這是一個以 Perl 6 物件模型為基礎的模組,CPAN 上寫道:<br /><blockquote>Moose is <i>based</i> on the prototypes and experiments I did for the Perl 6 meta-model. However, Moose is <b>NOT</b> an experiment/prototype; it is for <b>real</b>.</blockquote><br />如此,你可以類似 Perl 6 的寫法在 Perl 5 上寫 OO. :-)<br />這種寫法比較直觀,並且功能也比較強大。<pre class="code">package Point;<br />use Moose; # automatically turns on strict and warnings<br /> <br />has 'x' => (is => 'rw', isa => 'Int');<br />has 'y' => (is => 'rw', isa => 'Int');<br /><br />sub clear {<br /> my $self = shift;<br /> $self->x(0);<br /> $self->y(0); <br />}<br /><br />package Point3D;<br />use Moose;<br /><br />extends 'Point';<br /><br />has 'z' => (is => 'rw', isa => 'Int');<br /><br />after 'clear' => sub {<br /> my $self = shift;<br /> $self->z(0);<br />}; </pre>其他對 Moose.pm 的疑問就上 CPAN 的 <a href="http://search.cpan.org/%7Estevan/Moose-0.25/lib/Moose.pm">Moose.pm</a> 看吧! :)<br /><br />那個..裝 CPAN 模組是這樣裝的:<br /><br /><code>$ cpan Moose</code></content>
by c9s at September 25, 2007 05:00 PM
September 24, 2007
I was looking for the Printer Module on CPAN , and I found this ( <a href="http://search.cpan.org/%7Ewasx/Win32-Printer-0.9.0/Printer.pm">Win32::Printer</a> ). The author said that " PPD ( binary package ) is on the waxs.net " , but the link missed.<br /><br />I have to compile it by myself , it's a troublesome job , because I have to install MSVC 6.0.<br /><br />After you install MSVC 6.0 , just compile the module:<br /><br /><code>&gt; perl Makefile.PL<br />&gt; nmake<br />&gt; nmake install</code><br /><br />but you shall encounter an error which is that "PageNumber" is not in the structure "PSINJECTDATA".<br /><br />I don't know why. Maybe it was caused by the version of Win32 API Headers. the structure which the module code expects is:<br /><pre class="code">struct PSINJECTDATA {<br />DWORD DataBytes;<br />WORD InjectionPoint;<br />WORD PageNumber;<br />}<br />alias PSINJECTDATA* PPSINJECTDATA;</pre>but what I actually have is:<pre class="code">typedef struct _PSINJECTDATA {<br /><br />DWORD DataBytes; /* number of raw data bytes */<br />DWORD InjectionPoint; /* injection point */<br />DWORD Flags; /* flags */<br />DWORD Reserved; /* reserved field - must be 0 */<br /><br />/* Followed by raw data to be injected */<br /><br />} PSINJECTDATA, *PPSINJECTDATA;</pre>My solution is ...<br />just comment the line:<br /><br /><code>psd.PageNumber = page;</code><br /><br />then it unexpectedly can work out! :P<br /><br />I can't guarantee that "<a href="http://search.cpan.org/%7Ewasx/Win32-Printer-0.9.0/Printer.pm#Inject">inject</a>" function could work , but the <a href="http://search.cpan.org/%7Ewasx/Win32-Printer-0.9.0/Printer.pm#SYNOPSIS">test script</a> still prints out the example normally.</content>
by c9s at September 24, 2007 10:00 AM
在 Windows 底下寫東西都很麻煩... ( 都不能用 apt )<br /><br />如果 Perl 要用 OpenGL 那還得裝一下 <a href="http://www.bribes.org/perl/wopengl.html">OpenGL for Win32</a><br /><br />不過有 ppm 就比較簡單了:<br /><br /><code>ppm install http://www.bribes.org/perl/ppm/OpenGL.ppd</code></content>
by c9s at September 24, 2007 05:00 AM
遲早要在 Windows 上頭跑 Perl 的。所以裝了 ActivePerl,沒想到眼花去裝到 5.6 ,想說奇怪圖示怎麼這麼醜,印象中之前裝的還不錯看的。 XD<br /><br />首先要解決 Printer 的問題,結果沒想到 CPAN 上 Win32::Printer 的 Binary 不知道跑哪了,沒辦法裝。只好裝爛到爆 MS Visual C++ 6 ( 仍是不屑裝 MS .NET。 自由軟體的好處就是什麼都好取得,自從習慣了 FS 之後,對 MS, ASP, BASIC 什麼的,都很反感。)<br /><br />之後直接裝 <a href="http://www.lostmind.de/gtk2-perl/">gtk2-perl</a>,首先得裝 ActivePerl ,接著是 Gtk2 Runtime , Glade 也可以抓下來。<br /><br />接下來步驟可能會有點麻煩,因為要到各模組內的資料夾執行 ppm install 已經編譯好的 binary,所以我寫了一個 script 來跑,這樣以後安裝可以省事多。<br /><br />你可以先將各資料夾照順序編號,如:<br /><br />C:\foo\<br />00-ExtUtils-Depends-0.205<br />01-ExtUtils-PkgConfig-1.07<br />[...]<br /><br />接著在 foo 底下寫一個 install.pl 檔<pre class="code">#!/usr/bin/perl<br />qx{ppm repo add http://www.lostmind.de/gtk2-perl/ppm/};<br />qx{ppm install Gtk2};<br />for $dir ( <*> ) {<br /> next unless ( -d $dir );<br /> chdir $dir;<br /> for ( <*.ppd> ) { qx{ppm install $_}; }<br /> chdir "..";<br />}</pre>執行他即可。<br /><br />還是要婊一下,cmd.exe 爛死了,難用到爆,還寫那種什麼 WSH ? 才不要!<br /><br />對了,只要裝了 <a href="http://www.mingw.org/">Mingw - MSYS</a> 就可以直接在 cmd.exe 底下跑 sh , ls , vim 等等東西。帥</content>
by c9s at September 24, 2007 04:00 AM
September 22, 2007
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp0.blogger.com/_i3PNCkrh-3k/RvSKctskNsI/AAAAAAAAAu4/WCEDA8fulWw/s1600-h/glade.png"><img style="cursor: pointer;" src="http://bp0.blogger.com/_i3PNCkrh-3k/RvSKctskNsI/AAAAAAAAAu4/WCEDA8fulWw/s320/glade.png" alt="" id="BLOGGER_PHOTO_ID_5112863702879844034" border="0" /></a><br /><br />試用了 Glade 3 ,還不賴,比之前的 glade 好很多。<br /><br />接著用 Perl 的 <a href="http://search.cpan.org/dist/Gtk2-GladeXML/">GladeXML</a> ,試了一下 examples 底下的 fileman.pl<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp1.blogger.com/_i3PNCkrh-3k/RvSOQ9skNtI/AAAAAAAAAvA/SH898frKPAk/s1600-h/fileman.pl.png"><img style="cursor: pointer;" src="http://bp1.blogger.com/_i3PNCkrh-3k/RvSOQ9skNtI/AAAAAAAAAvA/SH898frKPAk/s320/fileman.pl.png" alt="" id="BLOGGER_PHOTO_ID_5112867899062892242" border="0" /></a><br /><br />希望能滿足我的需求才是...XD</content>
by c9s at September 22, 2007 04:00 AM
September 15, 2007
Pugs 是目前 Perl6 最完整的實作。 關於 Pugs 的 interview 在這裡看到 <a href="http://www.perl.com/pub/a/2005/03/03/pugs_interview.html">A Plan for Pugs</a> 。 ( 雖然是兩年前的東西了 )<br /><br />讓 Autrijus 大師注意到 Haskell 的原因是起源於覺得 SVK 不夠彈性,於是換了 Haskell 寫的 <a href="http://en.wikipedia.org/wiki/Darcs">Darcs</a> 來使用。Autrijus 花了一個月就學 Haskell 。而後 Autrijus 說服了他的委託人 Perl5 缺乏 COW ( Copy-on-write ) 的機制,出資讓他以 haskell 開發更好的 Library.<br /><br />在開發的過程中,Autrijus 發現到 Haskell 的優異, Autrijus 說:<br /><blockquote>But I digress. Using Haskell to develop OpenAFP.hs led to programs that eat constant 2MB memory, scale linearly, and are generally 2OOM faster than my Perl library.<br /><br />Oh, and the code size is 1/10.</blockquote>這是他發起 Pugs 的其中一個動機。接著他買了許多書,像是 <a href="http://www.cis.upenn.edu/%7Ebcpierce/tapl/index.html">TaPL</a> , <a href="http://www.cis.upenn.edu/%7Ebcpierce/attapl/index.html">ATTaPL</a> 等。<br /><blockquote>Autrijus:<br /><br />Anyway. So, I ordered a bunch of books online including TaPL and ATTaPL so I could learn more about mysterious things like Category Theory and Type Inference and Curry-Howard Correspondence.</blockquote>於是,Pugs 就這樣起來了。 :-) 當然詳細的 interview 請參閱 <a href="http://www.perl.com/pub/a/2005/03/03/pugs_interview.html">perl.com: A Plan for Pugs</a><br /><br />在 use Perl; 上頭,也有幾篇紀念性的 Announcement 譬如說: <a href="http://use.perl.org/%7Eautrijus/journal/22965">"Day 1: Pugs"</a> , <a href="http://use.perl.org/%7Eautrijus/journal/23446">"Day 29: A new month begins."</a> 等等。<br /><br />Pugs 的 Code 在每個模組的開頭幾行都有些有趣的 Quote,應該是 Autrijus 寫下的,譬如說 Class.pm 內的開頭幾行:<pre class="code">{-|<br />Class meta-model. (object meta-meta-model)<br /><br />> Learn now the lore of Living Creatures!<br />> First name the four, the free peoples:<br />> Eldest of all, the elf-children;<br />> Dwarf the delver, dark are his houses;<br />> Ent the earthborn, old as mountains;<br />> Man the mortal, master of horses...<br />-}</pre><br />或許是因為 Haskell 的關係,Perl 6 新增了許多類似 Haskell 的概念、功能,可參考 <a href="http://dev.perl.org/perl6/doc/synopsis.html">Synopses</a> 或 <a href="http://tokyo2007.yapcasia.org/sessions/2007/02/perl_6_today.html">YAPC: Perl 6 Today</a>。<br /><h3></h3><h3></h3></content>
by c9s at September 15, 2007 08:00 PM
August 26, 2007
昨天早上 Survey 了一下 Python ,發覺 Python 和 Perl 的哲學比較起來,頗有同工異曲之妙。<br /><br />Python 設計的很簡潔,怎麼說呢? Python 把分號拿掉了,並且嚴格限制縮排,此外 {,} 也拿掉了,所以語法很清晰,不用花精力在調整括號的排版,也不會有差異太大的 Coding Style。除此之外,物件導向方面設計的比較完善,譬如說<br /><br /><code>"String1".startswith("Str")</code><br /><br />同樣的語法在 Perl 裡頭就無法做到了。<br /><br />Python 相較於 Perl ,Perl 強調的是自由度,甚至自由到能夠改變剖析的語法,另外 perl 走的哲學就是 『條條大路通羅馬』一種目的可以用多種方式達到,可以很寫的很髒 - 可寫不可讀,或者寫的很精緻。 Perl 也提供很多的方便性,譬如樣式比對可由自己想要的字元取代雙引號,如此一來可以避免過多的跳脫的反斜線,像是 rx{ls},qq/String/,q-String- ;呼叫函數可以加上圓括號或是不加也可等等,透徹的利用很多特殊符號來達到簡略迅速的寫法。<br /><br />不過目前的 Perl 最大的一個缺點就是在物件導向方面不大自然,要透過 bless 函數利用 reference 的方式達到物件導向的目的,所以語法上比較不是這麼的簡潔,如下範例 ( 取自 <cite>WWW-Mechanize-1.30-jFIVC5</cite> 的 Image.pm :<pre class="code"><span style="color: rgb(102, 51, 255);">package</span> WWW::Mechanize::Image;<br /><br />...略<br /><br />sub new {<br /><span style="color: rgb(102, 51, 255);"> my</span> <span style="color: rgb(204, 51, 204);">$class</span> = <span style="color: rgb(255, 102, 0);">shift</span> ;<br /><span style="color: rgb(102, 51, 255);"> my</span> <span style="color: rgb(204, 51, 204);">$parms</span> = <span style="color: rgb(255, 102, 0);">shift</span> || {} ;<br /><br /><span style="color: rgb(102, 51, 255);"> my</span> <span style="color: rgb(204, 51, 204);">$self</span> = {};<br /><br /><span style="color: rgb(102, 51, 255);"> for</span> my <span style="color: rgb(204, 51, 204);">$parm</span> ( qw( url base tag height width alt name ) ) {<br /> $self->{$parm} = $parms->{$parm} if defined $parms->{$parm};<br /> }<br /><br /><span style="color: rgb(102, 51, 255);"> return</span> bless <span style="color: rgb(204, 51, 204);">$self</span>, <span style="color: rgb(204, 51, 204);">$class</span>;<br />}<br /></pre> 你可以發現要透過 shift class , 接著要實作一個雜湊參照,接著利用 bless 使他成為物件,最後傳回。<br /><br />Perl 在傳遞參數方面也是有些累贅,得利用 shift 或是 @_ 來取得參數。不過以上問題在 Perl 6 都會有革命性的改進,想更進一步瞭解可以參考 <cite><a href="http://dev.perl.org/perl6/doc/synopsis.html">Perl 6 Synopses</a></cite> 。<br /><br />Python 在這方面顯得精簡許多,如下範例 ( 取自 <a href="http://www.amk.ca/python/simple/"><cite>Simple Sample of Python</cite></a> )<br /><pre class="code"><span style="color: rgb(51, 51, 255); font-weight: bold;"></span><span style="color: rgb(51, 51, 255); font-weight: bold;">class</span> PrinterFormatter:<br /><span style="font-weight: bold;"> def</span> __init__(self, filename, page_len=58):<br /> # Save the time of creation for inclusion in the header<br /> import time<br /> self.now=time.asctime(time.localtime(time.time()))<br /><br /> .... 略<br /><br /><span style="font-weight: bold;"> def</span> write_header(self):<br /> # If the header for this page has just been written, don't<br /> # write another one.<br /><br /> .... 略<br /></pre>由於省略了大括號,只利用冒號代表接續的敘述,強迫縮排,參數傳遞的寫法也比較乾淨。簡單的說, Python 在語法的限制比較高,不過也因為如此而能夠將程式碼的可讀性提高。<br /><br />另外發覺 Python 與 Application 的 binding 也都不錯,而 Perl 的模組量多非常豐富、範圍較廣。所以雖然哲學上大相逕庭,不過各有其優缺點。<br /><br />以上,初步認識 Python 之感想。如有錯誤煩請指正,小弟懂的不多,請多多指教,謝謝。 :-)</content>
by c9s at August 26, 2007 03:00 PM
August 18, 2007
<a href="http://yapc.g.hatena.ne.jp/jkondo/">Visual Basic 最高! (audio)</a> <a href="http://www.archive.org/details/YAPCAsia2006TokyoLightningTalkVisualBasic">(video)</a><br />不過 video的部份,Internet Archive 收錄不是很完整<br />external: <a href="http://www.archive.org/search.php?query=subject:%22yapc%22">YAPC ( internet archive )</a></content>
by c9s at August 18, 2007 12:46 PM
<embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=-3876155376103839772&hl=en" flashvars=""> </embed></content>
by c9s at August 18, 2007 12:46 PM
<table align="right"><tbody><tr><td><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_i3PNCkrh-3k/Rqgo8u4K9BI/AAAAAAAAAi8/DIVSUMgqNzE/s1600-h/allison_autrijus.jpg"><img style="cursor: pointer;" src="http://bp2.blogger.com/_i3PNCkrh-3k/Rqgo8u4K9BI/AAAAAAAAAi8/DIVSUMgqNzE/s320/allison_autrijus.jpg" alt="" id="BLOGGER_PHOTO_ID_5091364402583237650" border="0" /></a></td></tr><tr><td><small>Allison Randal &amp; 唐鳳<br />Photo James Duncan Davidson/O'Reilly Media</small><br /></td></tr></tbody></table>Perl Hacker <a href="http://www.lohutok.net/">Allison Randal</a> 在她的網站上放了她的<a href="http://www.lohutok.net/talks/compiler_tools.pdf">簡報</a> - "<a href="http://www.parrotcode.org/docs/compiler_tools.html">Parrot Compiler Tools</a>",裡頭闡述了 Parrot 的架構、文法引擎等原理。<br /><br />此外 Allison Randal 最近被頒予 2007 White Camel 獎, 引述 <a href="http://use.perl.org/article.pl?sid=07/07/25/1617256">use Perl</a> 的消息:<br /><blockquote>Allison Randal<br /><br />[0]Allison is at the center of the Perl community. She's been<br />president of The Perl Foundation, a leader and manager of various<br />parts of the Perl 6 and Parrot efforts, as well a Perl author and<br />editor. Her latest contribution to Perl is version 2 of the<br />Artistic License, under which most open source Perl code, and Perl<br />itself, is licensesd "under the terms of Perl itself".</blockquote>External:<br />flickr <a href="http://www.flickr.com/photos/pdcawley/252428859/in/set-72157594298984945/">[1]</a> <a href="http://www.flickr.com/photos/x180/202613770/in/set-72157594209209708/">[2]</a><br /><a href="http://use.perl.org/article.pl?sid=07/07/25/1617256">use Perl</a></content>
by c9s at August 18, 2007 12:46 PM
<a href="http://use.perl.org/articles/07/06/18/1726249.shtml">http://use.perl.org/articles/07/06/18/1726249.shtml</a><br /><br />來自 Use Perl; 的新聞,<a href="http://www252.pair.com/comdog/">Brian d foy</a> 製作了一份關於學習 Perl6 的簡報以及錄音,可至上方連結下載。<br /><br />其他:<br /><br /><a href="http://blog.sina.com.tw/872/article.php?pbgid=872&amp;entryid=42944">開始學習 Perl 6 </a></content>
by c9s at August 18, 2007 12:46 PM
<a href="http://use.perl.org/articles/07/06/20/0311202.shtml">http://use.perl.org/articles/07/06/20/0311202.shtml</a><br /><br />把 Parrot 0.4.13 Release News 稍微看了一下,原來 Php 也在 <a href="http://parrotcode.org/">Parrot</a> 要吃的範圍之內,專案代號叫做 Plumhead,全名是 <a href="http://en.wikipedia.org/wiki/Plum-headed_Parakeet">"Plum-headed_Parakeet"</a> ( 梅子頭鸚鵡? )<br /><br />其他更新的項目像是 Perl6 , Lisp, Lua, Python ("Pynie"), ABC, WMLScript, and Tcl ("ParTcl") 這些語言也都在 Parrot 的範圍當中,可以說是吃很大 ( <a href="http://www.parrotcode.org/languages/">完整語言列表</a> )。<br /><br />在 <a href="http://www.perlfoundation.org/parrot/index.cgi?plumhead">Plumhead</a> 的首頁上才得知,原來 Php 是以 lex , yacc 實做 parser ,其中實做 php parser 的有 <a href="http://phpcompiler.org/">phc</a> ( php compiler , but not yet compile php ) 可以產生 AST ( Abstract Syntax Tree ) 的 XML 輸出。</content>
by c9s at August 18, 2007 12:46 PM
Perl 5.9.5 Release<br /><a href="http://use.perl.org/articles/07/07/09/0655239.shtml">http://use.perl.org/articles/07/07/09/0655239.shtml</a><br /><br />所以 Perl 5.10 快出來了,正在暖身中,期待 Perl 5.10 帶來的效能革命,接下來就是要與 Perl 6 接軌。</content>
by c9s at August 18, 2007 12:46 PM
在 Perl 如果想做類似以下的處理:<br /><br /><code>print "Processing..."<br />do_something<br />print "Done"</code><br /><br />對以上這段程式,Perl 會自動幫你做 Buffering , 於是會先印出 Processing...Done 然後才會開始 do_something. 解決的方式如下:<br /><br />Turn off buffering:<br /><br /><code>$|=1;</code></content>
by c9s at August 18, 2007 12:46 PM
恩,這是 Perl OO 的方式,如果要在 Class 裡面塞一個 Array ...我覺得這種方式實在很彆扭.. .用 <a href="http://www.blogger.com/www.theperlreview.com/Articles/v0i0/structured_classes.pdf">Class::Structured</a> 也沒有好到哪裡去... Orz<br />Perl 6 趕快成熟吧,我想要<a href="http://en.wikipedia.org/wiki/Perl_6#Object-oriented_programming">這樣寫</a>。<br /><pre class="code">#!/usr/bin/perl<br />use strict;<br /><br />package TEST;<br />sub new {<br />my $class = shift;<br />my $self = {<br /> i => 0<br />};<br />bless $self,$class;<br />return $self;<br />}<br /><br />sub push {<br />my $self = shift;<br />push @{$self->{queue}} , $self->{i} ;<br />$self->{i}++;<br />}<br /><br />sub pop {<br />my $self = shift;<br />return pop @{ $self->{queue} };<br />}<br /><br />1;<br /><br />package main;<br /><br />my $t = new TEST;<br />$t->push();<br />$t->push();<br />$t->push();<br />print $t->pop();<br /><br />1;</pre></content>
by c9s at August 18, 2007 12:46 PM
真好玩。 :P <br />Perl 真好用。</content>
by c9s at August 18, 2007 12:46 PM
<a href="http://mag-sol.com/train/teachin/">Perl Teach-In</a> from <a href="http://london.pm.org/">London.pm</a><br /><a href="http://tetralet.luna.com.tw/index.php?op=ViewArticle&articleId=174&blogId=1">Linuxer - 不會抱怨的一群人</a><br /><a href="http://ubuntu.wordpress.com/2007/05/21/300-easily-installed-free-fonts-for-ubuntu/">300+ Easily Installed Free Fonts for Ubuntu May 21, 2007</a><br /><a href="http://ubuntuforums.org/showthread.php?t=20976">HOWTO: Hoary ClearType-like fonts</a><br /><br /># 筆電慢到爆炸,不知道"今天" Presentation 會不會出錯,祈禱 OpenOffice 不要給我脫線...</content>
by c9s at August 18, 2007 12:46 PM
在 Catalyst::Manual 的 Tutorial 上只講到如何建立 TTSite Template ,但是如果要讓不同 Controller 都能有不同的 Template 該如何做? <br /><br />一般來說, TTSite 建立的 template 會放在 root/src , root/lib 。<br />Project Name 以 MyApp 為例 , 我們先建立 Cart 的 View<br /><code>$ script/MyApp_create.pl View Cart TTSite</code><br />之後,將原本的 root 內的 src , lib 搬到 root/cart/ 內,接下來,編輯 lib/MyApp/View/Cart.pm:<br /><pre class=code> 6 __PACKAGE__->config({ <br /> 7 CATALYST_VAR => 'Catalyst',<br /> 8 INCLUDE_PATH => [<br /> 9 MyApp->path_to( 'root','src' ),<br /> 10 MyApp->path_to( 'root','lib' )<br /> 11 ],<br /> 12 PRE_PROCESS => 'config/main',<br /> 13 WRAPPER => 'site/wrapper',<br /> 14 ERROR => 'error.tt2',<br /> 15 TIMER => 0<br /> 16 });</pre>將 path_to 設成:<pre class=code> 6 __PACKAGE__->config({ <br /> 7 CATALYST_VAR => 'Catalyst',<br /> 8 INCLUDE_PATH => [<br /> 9 MyApp->path_to( 'root','cart', 'src' ),<br /> 10 MyApp->path_to( 'root','cart', 'lib' )<br /> 11 ],<br /> 12 PRE_PROCESS => 'config/main',<br /> 13 WRAPPER => 'site/wrapper',<br /> 14 ERROR => 'error.tt2',<br /> 15 TIMER => 0<br /> 16 });</pre>最後只需要在 Cart 的 Controller 加上:<pre class=code> 28 sub end : ActionClass('RenderView') { <br /> 29 my ( $self , $c ) = @_;<br /> 30 $c->forward('MyApp::View::Cart')<br /> 31 unless ( $c->res->body || !$c->stash->{template} );<br /> 32 }</pre>將 RenderView 導向到 Cart,完工。<br /><br />Ref:<br />[1] <a href="http://search.cpan.org/~sri/Catalyst-5.61/lib/Catalyst/Manual/Cookbook.pod">http://search.cpan.org/~sri/Catalyst-5.61/lib/Catalyst/Manual/Cookbook.pod</a><br />[2] <a href="http://search.cpan.org/~mramberg/Catalyst-View-TT-0.25/lib/Catalyst/View/TT.pm">http://search.cpan.org/~mramberg/Catalyst-View-TT-0.25/lib/Catalyst/View/TT.pm</a></content>
by c9s at August 18, 2007 12:46 PM
如果在 Controller 內有用到 <pre class=code>$c->response->redirect();</pre><br />以及<pre class=code>109 sub end : ActionClass('RenderView') { <br />110 my ( $self , $c ) = @_;<br />111 $c->forward('MyApp1::View::Account');<br />113 }</pre>在 RenderView 時,因為沒有指定 $c->stash->{template} ,因此最後在做 RenderView 時會出現 file not find。 因此 RenderView 要加上:<pre class=code>109 sub end : ActionClass('RenderView') { <br />110 my ( $self , $c ) = @_;<br />111 $c->forward('MyApp1::View::Account')<br />112 unless ( $c->res->body || !$c->stash->{template} );<br />113 }</pre>這樣就會只在有指定 template 的時候,才會導向到 Account 的 View 。</content>
by c9s at August 18, 2007 12:46 PM