网络书屋(Web Reading Room)

A blogging framework for hackers.

Perl中文乱码问题

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

PerlFile.pl测试源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env perl 
#===============================================================================
#
#         FILE: perlFile.pl
#
#        USAGE: ./perlFile.pl  
#
#  DESCRIPTION: 
#
#      OPTIONS: ---
# REQUIREMENTS: ---
#         BUGS: ---
#        NOTES: ---
#       AUTHOR: YOUR NAME (), 
# ORGANIZATION: 
#      VERSION: 1.0
#      CREATED: 2017/2/8 9:49:51
#     REVISION: ---
#===============================================================================

use strict;
use warnings;
use utf8;



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

while ( <> ) {
    chomp;
    print $_,"\n";
    last if $_ =~ m/q/xm;
}

open(FEIJI,"E:\\feiji.txt") or die "can't open the file \n";
my $car ="尾翼";

   binmode(FEIJI,":encoding(gb2312)");
# binmode( STDIN,  ':encoding(gbk2312)' );
 #binmode( FEIJI,  ':encoding(utf8)' );
 #binmode( STDOUT, ':encoding(gbk2312)' );   
 #binmode( STDERR, ':encoding(gbk2312)' ); 
#while( my $line = <FEIJI>){
#my $re = Encode::decode('GB2312','汽车');
 my $count=1;
 while( <FEIJI>){
     #print "$_ \n" ;
    #     print "$_ \n" if $_ =~ /.*$re.*/;
#    Encode::_utf8_on($_);
    #    Encode::decode_utf8($_);
    #print "$_\n" ;#if $_ =~ m/$car/xm;
    #print "$count: $_\n" if $_ =~ m/$car/xm;
    #$count +=1;

     s/汽车/风力机/g;
    print;
    }