星期一, 1月 31, 2005

copy from perl cookbook

Here's some example code that uses these parameters:

use Logfile::Rotate;
$logfile = new Logfile::Rotate(
File => "/var/adm/log/syslog",
Count => 5,
Gzip => "/usr/local/bin/gzip",
Signal =>
sub {
open PID, "/etc/syslog.pid" or
die "Unable to open pid file:$!\n";
chomp($pid = );
close PID;
# should check validity first
kill 'HUP', $pid;
}
);
This locks the log file you've specified and prepares the module for rotating it. Once you've created this object, actually rotating the log is trivial:

$logfile->rotate( );
undef $logfile;

星期五, 1月 28, 2005

utf2big5.pl

use Unicode::String qw(utf7 utf8 utf16);
use Unicode::Map;

$sszUTFFilename = @ARGV[0];
$sszUTFType = @ARGV[1];

open(UTFFILE, $sszUTFFilename) or die("can't open $sszUTFFilename: $!");
@aszLines = ;
$sszOneLine = join("", @aszLines);
close(UTFFILE);
$oBig5Map = Unicode::Map->new("cp950") || die("can't create Unicode::Map
object: $!");

if ($sszUTFType eq 'utf7') {
$oUtf = utf7($sszOneLine);
} elsif ($sszUTFType eq 'utf8') { $oUtf = utf8($sszOneLine);
} else { die("unknown utf type: $sszUTFType");
}
$sszBig5OneLine = $oBig5Map->to8($oUtf->utf16);
unlink($sszUTFFilename);
open(BIG5FILE, ">$sszUTFFilename") or die("can't create $sszUTFFilename:
$!");
print BIG5FILE $sszBig5OneLine;
close(BIG5FILE);

gb2312 utf-8 相互转换

$filename = http://smsrc.sina.com.cn/newsinarc/include/gb2utf8.txt
//对照表的使用
$filename = "gb2utf8.txt";
$fp = fopen($filename,"r");
while(! feof($fp)) {
list($gb,$utf8) = fgetcsv($fp,10);
$charset[$gb] = $utf8;
}
fclose($fp);
//以上读取对照表到数组备用

/** gb2312到utf-8 **/
function gb2utf8($text, &$charset) {
//提取文本中的成分,汉字为一个元素,连续的非汉字为一个元素
preg_match_all("/(?:[\x80-\xff].)|[\x01-\x7f]+/",$text,$tmp);
$tmp = $tmp[0];
//分离出汉字
$ar = array_intersect($tmp, array_keys($charset));
//替换汉字编码
foreach($ar as $k=>$v)
$tmp[$k] = $charset[$v];
//返回换码后的串
return join('',$tmp);
}

/** utf-8到gb2312 **/
function utf82gb($text, &$charset) {
$p = "/[xf0-xf7][x80-xbf]{3}|[xe0-xef][x80-xbf]{2}|[xc2-xdf][x80-xbf]|[x01-x7f]+/";
preg_match_all($p,$text,$r);
$utf8 = array_flip($charset);
foreach($r[0] as $k=>$v)
if(isset($utf8[$v]))
$r[0][$k] = $utf8[$v];
return join('',$r[0]);
}

//测试
$s = gb2utf8('这是对照表的测试', $charset);
echo utf82gb($s, $charset);
?>

[perl] 關於部分字元會產生亂碼的問題??

※ 引述《snowfly.bbs@zoo.ee.ntu.edu.tw (飄然似雪)》之銘言:
> 哇哇...終於有高手做成模組了...

不敢當.

> 之前小弟有看過簡繁轉換的程式
> 但是那個程式似乎寫ㄉ不是很好
> 她是先把字設成變數然後再去變數轉陣列....

對, 那是 Lingua::ZH::HanConvert. 就是因為太慢纔想要自己寫的.

http://autrijus.org/Encode-HanConvert-0.02.tar.gz 是新版. 我可能
會收集大家用的意見之後, 加上測試檔做成 0.03.

> 解說一下該如何使用您所寫出來的模組呢?

裝完之後, perldoc Encode::HanConvert 就是了. 要 5.7.2+, 最好是
等這兩天會出來的 5.7.3; 5.7.2 的 big5 表是我還沒校過的版本, 在
點符號上有問題.

又, 模組附有 b2g.pl 和 g2b.pl 兩個可執行檔, 可以直接用, 也可以
參考 perldoc b2g.pl 看用法.

稍微抄一下:

use Encode::HanConvert; # needs perl 5.7.2 or better

# 簡繁互轉
$euc_cn = big5_to_gb($big5); # Big5 to GB2312 (EUC-CN encoding)
$big5 = gb_to_big5($euc_cn); # GB2312 to Big5

# 就地轉換 (適用於所有函式)
big5_to_gb($string); # transform $string from big5 to gb
gb_to_big5($string); # ditto.

# Unicode 簡繁互轉
$simp = trad_to_simp($trad); # Traditional to Simplified
$trad = simp_to_trad($trad); # Simplified to Traditional

# 繁/簡區域碼轉簡/繁 Unicode
$simp = big5_to_simp($big5); # Big5 to Simplified
$big5 = simp_to_big5($simp); # Simplified to Big5
$trad = gb_to_trad($euc_cn); # GB2312 to Traditional
$euc_cn = trad_to_gb($trad); # Traditional to GB2312

# 不做轉換, 祗是變 Unicode
$simp = gb_to_simp($euc_cn); # GB2312 to Simplified
$euc_cn = simp_to_gb($simp); # Simplified to GB2312
$trad = big5_to_trad($big5); # Big5 to Traditional
$big5 = trad_to_big5($trad); # Traditional to Big5

# 如果本來就在用 Lingua::ZH::HanConvert, 就可以直接代換:
use Encode::HanConvert qw(trad simple); # not exported by default
$simp = simple($trad); # Traditional to Simplified
$trad = trad($trad); # Simplified to Traditional

# 用 I/O discipline 自動轉換
require Encode::CN;
open BIG5, ':encoding(big5-simp)', 'big5.txt'; # Big5 => Simp
open EUC, '>:encoding(euc-cn)', 'euc-cn.txt'; # Simp => GB2312
print EUC, ;

require Encode::TW;
open EUC, ':encoding(euc-cn-trad)', 'euc-cn.txt'; # GB2312 => Trad
open BIG5, '>:encoding(big5)', 'big5.txt'; # Trad => Big5
print BIG5, ;

# 程式內的 Big5 雙引號內字串一律當做簡體 Unicode
use encoding 'big5-simp';
print "繁體"; # prints simplified chinese in unicode
binmode(STDIN, ':encoding(euc-cn)'); # 用 GB2312 輸出
print "繁體"; # prints simplified chinese in GB2312/EUC-CN

要注意的是, 在 Perl 裡, 我們平常說的 GB2312 要寫成 euc-cn, 不是
gb2312. 或是寫 'gbk' 也可以.

星期四, 1月 27, 2005

Unicode::String::utf16($utf16)->utf8;

Google 群組:查看留言及回應
"謝謝! 謝謝您的指導,已成功了。附下程式碼如下: #!/usr/local/bin/perl use Unicode::String; use Unicode::Map; my $map = new Unicode::Map('cp950'); $input="這是一個測試"; $utf16=$map->to16($input); $utf8=Unicode::String::utf16($utf16)->utf8; print $utf8; 原來我原先有些多餘的程式碼。另一方面,我的電腦上用 cp950 和 BIG5 現在都可以。 Have a nice day!"
http://groups.google.com/groups?hl=zh-TW&lr=&c2coff=1&frame=right&th=d27c7a777603077f&seekm=3iSbYh%24b45%40www.kkcity.com.tw#s

星期二, 1月 25, 2005

wretch broken again~ haha~ Posted by Hello

星期三, 1月 19, 2005

星期四, 1月 13, 2005

Yes Taiwan

Taiwan’s new 3 megapixel cameraphone, the X-cute V8

Taiwan’s new 3 megapixel cameraphone, the X-cute V8 - Engadget - www.engadget.com
"Taiwan’s new 3 megapixel cameraphone, the X-cute V8

Posted Jan 12, 2005, 4:08 PM ET by Ryan Block
Related entries: Cellphones

X-Cute V8

Seeing phones like this remind us that sometimes it’s so very easy to tell the difference—we mean really tell the difference—between Chinese and Taiwanese gear and, er, the rest of the world’s (okay, BenQ excepted). Don’t get us wrong, we’re not trying to harsh on Yan Chuan Communication’s mellow for being among the first outside Korea/Japan to bust out a 3-megapixel cameraphone, but the irony of the X-cute V8’s name may just be too great to comprehend, it looking toyish at best. In its defense, though, it can be used gun/DV cam-style, and it does have a 1.6-million color screen, mini-SD slot, and MP3 playback software."
http://www.engadget.com/entry/1234000160027154/

phlab >> MyMan

phlab >> MyMan: "What is MyMan?
MyMan is a shortcut for MySQL(TM) manual and it is conversion of this manual into HTML Help. This conversion tries to bring additional functionality and make using of MySQL manual more comfortable. Its content is not altered in any way. As a source for the conversion was used HTML version of MySQL manual available at http://www.mysql.com/Downloads/Manual/manual.zip. The conversion was made by using Html2hhp. "

星期三, 1月 05, 2005

Cingular successfully tests new 3G network - Engadget - www.engadget.com

Cingular successfully tests new 3G network - Engadget - www.engadget.com: "They used High-Speed Downlink Packet Access (HSDPA) technology to sustain rates of more than 3Mbps during the tests."

new word

嗯,好像不錯的產品

"personal media players (PMPs)"

ATnotes - Create notes on your desktop - FREEWARE - Redirect by ulimit.com

ATnotes - Create notes on your desktop - FREEWARE - Redirect by ulimit.com


ATnotes is a FREE program which creates notes on the Windows desktop. It lives in the system tray, takes very few resources, and supports a lot of languages.

星期二, 1月 04, 2005

Tip #19 - line numbers... : vim online

Tip #19 - line numbers... : vim onlinecreated: February 25, 2001 22:17 complexity: basic
author: scrott@users.sourceforge.net as of Vim: 5.7

I have started doing all my code reviews on a laptop because of the number command.

:set number will put line numbers along the left side of a window

:help number

星期日, 1月 02, 2005

健康幼稚園火燒車意外 12年官司終定讞

那年我開始跟我媽媽說:「這些人都要抓去槍斃!」

健康幼稚園火燒車意外 12年官司終定讞

記者黃貞茹、簡振書/台北報導 2005-01-01 12:30

健康幼稚園火燒車意外,經過12年的官司纏訟,幼稚園負責人、園長及教務主任等3人,在2004年的最後一天判刑確定。殉職林靖娟老師的年邁雙親,對於這樣的判決雖然不是很滿意,但兩位老人家都覺得累了,也不會再上訴。

Click here

女兒靖娟的房間一空就是12年,而這個火燒車官司也纏訟了12年。

民國81年,健康幼稚園教學旅遊,因為遊覽車老舊電源短路,引燃車上瓦斯並引發爆炸。捨己救人的老師林靖娟,包括當時刑事局長侯友宜的獨子侯乃維及其他學生,共23人不幸葬身火窟。

這個官司的刑事責任,號稱從幼稚園打到高中,終於在2004年的最後一天,以業務過失致死罪,將幼稚園負責人判刑。

因為沒有檢查遊覽車逃生門等設施,幼稚園負責人吳文道被判刑1年2個月,園長楊聰慧雖沒有同行,但因事前沒有巡視遊覽車狀況,判刑10個月,租車的教務主任趙國芳則判刑6個月,得易科罰金。

林靖娟的父母聽到這樣的判決結果,並不是很滿意,但是12年的煎熬,他們已經累了。

雖然兩老說得很淡,但是這12年他們是怎麼過的?喪女的辛酸,只有他們自己知道。"
http://news.yam.com/ettoday/society/200501/20050101796379.html