• perl unicode 字符转换


    <pre name="code" class="html">[root@dr-mysql01 ~]# cat a1.pl 
    my $str="$ARGV[0]";
    use Encode;  
    use Encode::CN;  
    use JSON;   
    use URI::Escape;  
    use LWP::Simple;  
    $str =~ s/\u([0-9a-fA-F]{4})/pack("U",,hex($1))/eg;    
    print "$str";
    
    
    [root@dr-mysql01 ~]# perl a1.pl "u767bu5f55u6210u529f"
    Wide character in print at a1.pl line 8.
    登录成功You have mail in /var/spool/mail/root
    
    
    需要encode_utf8:
    [root@dr-mysql01 ~]# cat a1.pl 
    my $str="$ARGV[0]";
    use Encode;  
    use Encode::CN;  
    use JSON;   
    use URI::Escape;  
    use LWP::Simple;  
    $str =~ s/\u([0-9a-fA-F]{4})/pack("U",,hex($1))/eg;    
    print encode_utf8($str);
    
    [root@dr-mysql01 ~]# perl a1.pl "u6e29u91d1u6240"
    温金所[root@dr-mysql01 ~]# 
    
    
    [root@dr-mysql01 ~]# cat hg.pl   
    use Encode;  
    use Encode::CN;  
    use JSON;   
    use URI::Escape;  
    use LWP::Simple;  
    open (LOG ,"<","hg.txt");  
    while (<LOG>){  
    $content=$_;  
    $content =~ s/\u([0-9a-fA-F]{4})/pack("U",,hex($1))/eg;    
    print "$content";  
    
    
    http://download.baoxianziliao.com/tha/u4fdd/u9669/u516c/u53f8/u7231/u5fc3/u6fc0/u52b1/u4f1a/u7684/u529f/u80fd/u4e0e/u8fd0/u4f5c/u8981/u988623/u9875.ppt"
    
    [root@dr-mysql01 ~]# cat a1.pl 
    my $str="gu4fddu9669u516cu53f8u7231u5fc3u6fc0u52b1u4f1au7684u529fu80fdu4e0eu8fd0u4f5cu8981u988623u9875.ppt";
    use Encode;  
    use Encode::CN;  
    use JSON;   
    use URI::Escape;  
    use LWP::Simple;  
    $str =~ s/\u([0-9a-fA-F]{4})/pack("U",,hex($1))/eg;    
    print "$str";
    
    [root@dr-mysql01 ~]# perl a1.pl 
    gu4fdd9669516c53f872315fc36fc052b14f1a7684529f80fd4e0e8fd04f5c89819886239875.ppt[root@dr-mysql01 ~]# 


    
    
    
                                        
    
  • 相关阅读:
    DBCC 常用命令
    查看数据库备份情况
    identity 列自动增长问题(SQL Server 2012 Auto Identity Column Value Jump Issue)
    job相关脚本
    Ad hoc update to system catalogs is not supported
    数据库加密&证书创建
    sp_MSforeachdb&sp_MSforeachtable&sp_MSforeachobject&查看某个对象的依赖对象
    session 学习
    Eclipse Python Djando 环境配置
    MySQL 日志文件与相关参数
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351151.html
Copyright © 2020-2023  润新知