[PerlChina] 【请教】perl提取网页TXT时候的乱码问题

Zhu Zhu zhuzhu at perlchina.org
Tue Apr 17 02:37:01 PDT 2007


没有遇到过,我只遇到过 1G - 2G 的日志处理,不过我不知道怎么才能合理读取这么 
大的文件,
要求是从日志文件中每天提取前一天的记录。到每个月 20号的时候就用差不多2G了, 
请问
对于这种大日志文件我该怎么做呢?


在 Tue, 17 Apr 2007 15:07:19 +0800,Achilles Xu <formalin14 at gmail.com> 写 
道:

> perl中处理中文的原则:
>
> 让中文字符串在perl中以utf8的形式存在。一个字符串进来的时候如果是其他编 
> 码,先转成utf8,出去的时候再转成相应的编码。这样可以保证任何操作都不出 
> 错。
>
> 在07-4-15,Dongxu Ma <dongxu.ma at gmail.com> 写道:
>>
>> yes, your input stream was encoded as GB2312.
>>
>> 在07-4-15,zongzi <honghunter at gmail.com> 写道:
>> >
>> > 就是说需要强制作一次转码才行?
>> >
>> > 在 07-4-13,Dongxu Ma<dongxu.ma at gmail.com> 写道:
>> > > `iconv -f GB2312 -t UTF8 p0.html' showed me Chinese inside that  
>> html,
>> > > which means while reading from html in your script, you need to  
>> decode
>> >
>> > > from GB2312. By something like:
>> > >
>> > > 1. Encode::decode("GB2312", <INPUT>)
>> > > 2. bindmode INPUT, ":encoding('GB2312')"
>> > >
>> > > 在07-4-13,zongzi < honghunter at gmail.com> 写道:
>> > > > 编辑器我用的UltraEdit32。
>> > > >
>> > > > 网页编码都是<meta http-equiv="Content-type" content="text/html;
>> > > > charset=gb2312"/>,还需要什么转换吗?
>> > > >
>> > > >
>> > > > 在 07-4-13,Beckheng Lam<beckheng at perlchina.org> 写道:
>> > > > > 是不是跟gbk或者utf8有关?
>> > > > >
>> > > > > 缘起和合 wrote:
>> > > > > 什么编辑器干的?确实很乱,用VIM吧
>> > > > >
>> > > > > On 4/12/07, zongzi <honghunter at gmail.com> wrote:
>> > > > > >
>> > > > >
>> > > 为了方便放在PDA上面看小说,我用wget把网页(是新浪读书频道)下载到本 
>> 机,然后用perl去把其中的正文提取出来。
>> > > > > >
>> > > > > > 发现弄出来的txt文档中,有好多乱码(用记事本打开看的时候)。
>> > > > > >
>> > > > > > 请教大家怎么才能解决?
>> > > > > >
>> > > > > >
>> > > > > > 附件是我的代码,写的非常乱。真是不好意思了。
>> > > > > >
>> > > > > > --
>> > > > > > 这是一个有钱人的世界,与我的世界截然不同!
>> > > > > >
>> > > > > > _______________________________________________
>> > > > > > China-pm mailing list
>> > > > > > China-pm at pm.org
>> > > > > > http://mail.pm.org/mailman/listinfo/china-pm
>> > > > > >
>> > > > > >
>> > > > >
>> > > > >
>> > > > >
>> > > > > --
>> > > > > ------======Nerazzurri======------
>> > > > > ________________________________
>> > > > >
>> > > > _______________________________________________
>> > > > China-pm
>> > > > > mailing
>> > > > > list
>> > > > China-pm at pm.org
>> > > > http://mail.pm.org/mailman/listinfo/china-pm
>> > > > >
>> > > > > _______________________________________________
>> > > > > China-pm mailing list
>> > > > > China-pm at pm.org
>> > > > > http://mail.pm.org/mailman/listinfo/china-pm
>> > > > >
>> > > >
>> > > >
>> > > > --
>> > > > 这是一个有钱人的世界,与我的世界截然不同!
>> > > > _______________________________________________
>> > > > China-pm mailing list
>> > > > China-pm at pm.org
>> > > > http://mail.pm.org/mailman/listinfo/china-pm
>> > >
>> > >
>> > >
>> > > --
>> > > cheers,
>> > > -dongxu
>> > > __END__
>> > > http://search.cpan.org/~dongxu <http://search.cpan.org/%7Edongxu>
>> > > _______________________________________________
>> > > China-pm mailing list
>> > > China-pm at pm.org
>> > > http://mail.pm.org/mailman/listinfo/china-pm
>> > >
>> >
>> >
>> > --
>> > 这是一个有钱人的世界,与我的世界截然不同!
>> > _______________________________________________
>> > China-pm mailing list
>> > China-pm at pm.org
>> > http://mail.pm.org/mailman/listinfo/china-pm
>>
>>
>>
>>
>> --
>> cheers,
>> -dongxu
>> __END__
>> http://search.cpan.org/~dongxu <http://search.cpan.org/%7Edongxu>
>>
>> _______________________________________________
>> China-pm mailing list
>> China-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/china-pm
>>
>
>
>



-- 
http://fred.webcan.cn


More information about the China-pm mailing list