How can I treat command-line arguments as UTF-8 in Perl?

后端 未结 5 706
醉酒成梦
醉酒成梦 2020-12-03 08:12

How do I treat the elements of @ARGV as UTF-8 in Perl?

Currently I\'m using the following work-around ..

use Encode qw(decode encode);

         


        
5条回答
  •  长情又很酷
    2020-12-03 08:26

    For example for windows set code

    chcp 1251
    

    in perl:

    use utf8;
    use Modern::Perl;
    use Encode::Locale qw(decode_argv);
    
     if (-t)
    {
        binmode(STDIN, ":encoding(console_in)");
        binmode(STDOUT, ":encoding(console_out)");
        binmode(STDERR, ":encoding(console_out)");
    }
    
    Encode::Locale::decode_argv();
    

    in command line

    perl -C ppixregexplain.pl qr/\bмама\b/i > ex1.html 2>&1  
    

    where ppixregexplain.pl

提交回复
热议问题