jueqingsizhe66 / jueqingsizhe66.github.io

my hugo blogs
0 stars 0 forks source link

blog/2017/02/08/perlzhong-wen-luan-ma-wen-ti/ #17

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

perl中文乱码问题 | 30年磨一剑

binmode可以很好的解决perl中问题,采用Encode1,Encode等方式不管用

https://jueqingsizhe66.github.io/blog/2017/02/08/perlzhong-wen-luan-ma-wen-ti/

jueqingsizhe66 commented 2 years ago

while( ){

foreach my $p (@$people) {
    $rec{$p}+=1 if $_=~m/$p/xm;
        #print $p,"\n"
}

}

foreach my $p (@$people){
    print $p,"\t",$rec{$p},"\n";
}
jueqingsizhe66 commented 2 years ago

增加统计打印功能

jueqingsizhe66 commented 2 years ago

$people=["人名1","人名2","人名3"]; ## 数组引用 binmode(STDIN,":encoding(gb2312)"); binmode(STDIN,":encoding(gbk)"); ## gbk的中文字数更多 gb2312次之 gb18030最少

jueqingsizhe66 commented 2 years ago

!/usr/bin/env perl

===============================================================================

#

FILE: perlFile.pl

#

USAGE: ./perlFile.pl

#

DESCRIPTION:

#

OPTIONS: ---

REQUIREMENTS: ---

BUGS: ---

NOTES: ---

AUTHOR: yzl

ORGANIZATION:

VERSION: 1.0

CREATED: 2017/2/8 9:49:51

REVISION: ---

===============================================================================

use strict; use warnings; use utf8; use Data::Dumper;

binmode(STDIN,":encoding(gbk)"); binmode(STDOUT,":encoding(gbk)");

my %rec; open(FEIJI,"haifeng.txt") or die "can't open the file \n";

my $people =["人民","人名"];

binmode(FEIJI,":encoding(gbk)"); my $count=1; while( ){ foreach my $p (@$people) { $rec{$p}+=1 if $_=~m/$p/xm; } }

foreach my $p (@$people){ print $p,"\t",$rec{$p},"\n"; }