- 论坛徽章:
- 0
|
- #!/usr/bin/perl -w
- # SCRIPT: u2g.pl
- # AUTHOR: Julynada
- # DATE: 2010/09/20
- # REV: 1.0
- # For Study
- #
- # PURPOSE:
- # 将UTF8编码的文本文件转换为GBK编码的文本文件 utf8 to gbk
- use Encode;
- use Encode::Guess;
- if ( @ARGV < 2 ) {
- die "Usage: u2g.pl source_file target_file\n";
- }
- open my $in, "<", $ARGV[0] or die;
- open my $out, ">", $ARGV[1] or die;
- my $enc;
- while (<$in>) {
- $enc = guess_encoding( $_, qw/utf8/ );
- if ( !ref($enc) ) {
- close $out;
- unlink $ARGV[1];
- die "Can't guess: $enc";
- }
- Encode::from_to( $_, "utf8", "gbk", 1 );
- print $out $_;
- }
复制代码 写出来了,请各位看看有没问题。 |
|