zoukankan      html  css  js  c++  java
  • 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 ~]# 


    
    
    
                                        
    
  • 相关阅读:
    implementaion bottle session with beaker
    [梦]20050802
    网站更新部署20100912
    Cherokee不值得推荐,你还是可以看一看
    最简单方法远程调试Python多进程子程序
    nginx相关的问题
    本地配置host解析的问题
    base target问题,
    在asp.net中自动合并小图片并使用css sprite显示出来
    html编辑器
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351151.html
Copyright © 2011-2022 走看看