404 Blog Not Found:perl - Text::Darts 0.02 Released!
でも余裕があればText::Txとかも作ってみたいところ。
眠れないので勢いにまかせて作っちゃいましたよ岡野原さん。
svn co http://svn.coderepos.org/share/lang/perl/Text-Tx
で取って下さい。
CPANに上げるのはまだ。理由はこれから書きます。
CPANにまだ上げない理由その一。txはlibraryとして素直に使うにはちょっと問題があるのです。
tx.cpp140: fprintf(stderr,"elemNum:%d nodeNum:%d\n",elemNum,nodeNum);
これ、tx::read()
の一部ですが、成功した場合もこれがstderrに出力されます。デバッグモードとかならとにかく、libraryでこれはいかがなものか。現時点ではText::Txはこれを回避するために
sub open{ my $pkg = shift; my $filename = shift; my $errfh; if (!$DEBUG){ # temporarily close STDERR to suppress messages from tx_tool::tx::read; open $errfh, '>&', \*STDERR or die "Can't dup STDERR: $!"; close STDERR; } my $dpi = xs_open($filename); if (!$DEBUG){ # and restore STDERR open STDERR, '>&', $errfh or die "Can't dup OLDERR: $!"; } carp __PACKAGE__, " cannot open $filename" unless $dpi; bless \$dpi, $pkg; }
という具合に、一時的にstderrを対比させるというアクロバットをしこんでいます。これはきもい。
もう一つは、なぜか Mac OS X v10.4.11 の gcc 4.0できちんとcompileしないこと。署名の後に様子を張っておきますが、なんだかむずがってます。
とはいうものの、Txは元のWord ListよりもTrieが小さくなるというのが涙が出るほど嬉しい。
#!/usr/local/bin/perl use strict; use warnings; use blib './Text-Tx/trunk'; use Text::Tx; my $tx = Text::Tx->open("words.tx"); sub say { print @_, "\n" }; say $tx->gsub("The quick brown fox jumps over the black lazy dog", sub{"<$_[0]>"}); print STDERR "wow\n"; # make sure STDERR is restored CORE::dump if @ARGV and shift eq 'dump';
ここでwords.txは/usr/share/dict/words
をtxbuild
したものですが、これを動かしてわざとcoreを吐かせたところ、FreeBSD 6-Stableで2512kB。
%wc /usr/share/dict/words 235882 235882 2493082 /usr/share/dict/words
ですから、これならmod_perlとかに組み込みで使うにも安心感があります。
Enjoy!
Dan the Perl Monger
OS Xでのmakeの結果cp lib/Text/Tx.pm blib/lib/Text/Tx.pm /usr/local/bin/perl /usr/local/lib/perl5/5.10.0/ExtUtils/xsubpp -C++ -typemap /usr/local/lib/perl5/5.10.0/ExtUtils/typemap Tx.xs > Tx.xsc && mv Tx.xsc Tx.c Please specify prototyping behavior for Tx.xs (see perlxs manual) g++ -c -I/usr/local/include/tx -fno-common -DPERL_DARWIN -no-cpp-precomp -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -g -pipe -Os -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" "-I/usr/local/lib/perl5/5.10.0/darwin-thread-multi-2level/CORE" Tx.c In file included from /usr/include/c++/4.0.0/bits/basic_ios.h:44, from /usr/include/c++/4.0.0/ios:50, from /usr/include/c++/4.0.0/ostream:44, from /usr/include/c++/4.0.0/iostream:44, from /usr/local/include/tx/tx.hpp:5, from Tx.xs:11: /usr/include/c++/4.0.0/bits/locale_facets.h:4314:40: error: macro "do_open" requires 7 arguments, but only 2 given /usr/include/c++/4.0.0/bits/locale_facets.h:4361:34: error: macro "do_close" requires 2 arguments, but only 1 given /usr/include/c++/4.0.0/bits/locale_facets.h:4380:55: error: macro "do_open" requires 7 arguments, but only 2 given /usr/include/c++/4.0.0/bits/locale_facets.h:4407:23: error: macro "do_close" requires 2 arguments, but only 1 given In file included from /usr/include/c++/4.0.0/bits/locale_facets.h:4491, from /usr/include/c++/4.0.0/bits/basic_ios.h:44, from /usr/include/c++/4.0.0/ios:50, from /usr/include/c++/4.0.0/ostream:44, from /usr/include/c++/4.0.0/iostream:44, from /usr/local/include/tx/tx.hpp:5, from Tx.xs:11: /usr/include/c++/4.0.0/i686-apple-darwin8/bits/messages_members.h:51:38: error: macro "do_open" requires 7 arguments, but only 2 given /usr/include/c++/4.0.0/i686-apple-darwin8/bits/messages_members.h:60:71: error: macro "do_open" requires 7 arguments, but only 2 given /usr/include/c++/4.0.0/i686-apple-darwin8/bits/messages_members.h:71:39: error: macro "do_close" requires 2 arguments, but only 1 given /usr/include/c++/4.0.0/bits/locale_facets.h:4380: error: 'do_open' declared as a 'virtual' field /usr/include/c++/4.0.0/bits/locale_facets.h:4380: error: expected ';' before 'const' /usr/include/c++/4.0.0/bits/locale_facets.h:4407: error: variable or field 'do_close' declared void /usr/include/c++/4.0.0/bits/locale_facets.h:4407: error: 'do_close' declared as a 'virtual' field /usr/include/c++/4.0.0/bits/locale_facets.h:4407: error: expected ';' before 'const' /usr/include/c++/4.0.0/i686-apple-darwin8/bits/messages_members.h:60: error: expected initializer before 'const' /usr/include/c++/4.0.0/i686-apple-darwin8/bits/messages_members.h:71: error: expected initializer before 'const' make: *** [Tx.o] Error 1
デフォルトでログが出力されてしまうのは確かにまずかったので、それらは関数で取得できるように変更しました(ver0.05)。試してみてください。
OS Xの方は再現する環境が今手元にないので、周りの人のでいろいろ試して見ます。