[Moscow.pm] Perl ?

Nikolay Mishin mi ya.ru
23 13:09:18 PDT 2014


   
Encode::Locale::decode_argv();

   
#!/usr/bin/env 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();
my $lang = shift or die "Usage: $0 What_is_your_language?\n"; 

 $lang =~ /
 (perl|) 
 (?{print "use Perl or die!!\n   !!";}) 
          /ix;

https://github.com/mishin/presentation/blob/master/100_regex_4_moscow_pm.pl

23.09.2014, 23:52, "Nikolay Mishin" <mi  ya.ru>:
> , 
> 
> $lang = decode(locale => $lang);
>   ,   !!
> https://github.com/mishin/presentation/blob/master/100_regex_4_moscow_pm.pl
>       
>
> if ($^O eq "MSWin32") {
> unless ($ENCODING_LOCALE) {
> # Try to obtain what the Windows ANSI code page is
> eval {
> unless (defined &GetACP) {
> require Win32::API;
> Win32::API->Import('kernel32', 'int GetACP()');
> };
> if (defined &GetACP) {
> my $cp = GetACP();
> $ENCODING_LOCALE = "cp$cp" if $cp;
> }
> };
> }
>
> 23.09.2014, 13:15, " " <ilvin  mail.ru>:
>> , !
>>
>>   Console::Locale.
>>   https://metacpan.org/pod/Encode::Locale
>>    ,      
>>  ,  .
>>
>>   STDIN, STDERR, STDOUT    
>>  ,   @ARGV   ,
>>   :
>>
>> my $lang = decode(locale => $ARGV[0]);
>>
>>    -  ,  - ...
>>
>>  ,
>>   .
>>
>> Mon, 22 Sep 2014 23:58:07 +0400  Nikolay Mishin <mi  ya.ru>:
>>> ,  ,  Text::Iconv
>>> -my $converter = Text::Iconv->new( "cp1251", "utf-8");
>>> -$lang = $converter->convert($lang);
>>> +Encode::from_to($lang, 'windows-1251', 'utf-8');
>>> https://github.com/mishin/presentation/commit/2d1ba8adcfc451d45454490b5bf442f95bd41e0a
>>>   ,
>>>  ,   ,  Encode::Detect::Detector
>>>   ISO-8859-7     windows-1251,
>>> ,      ,    ,
>>>  
>>>
>>> 22.09.2014, 12:51, " " <ilvin  mail.ru>:
>>>> , .
>>>>
>>>>  Perl    ,   UTF-8.    utf8.
>>>>     Perl,        utf8.
>>>>      UTF-8  utf8.
>>>>      Perl,        .
>>>>      utf8  UTF-8
>>>>
>>>>    Encode::encode('UTF-8', $string)  Encode::decode('UTF-8', $string).
>>>>
>>>> Text::Iconv -   ,          .
>>>>
>>>>      Perl  ,
>>>>        ...
>>>>
>>>> PS:         ,   
>>>>
>>>> binmode STDIN, ":encoding(console_in)" if -t STDIN; binmode STDOUT, ":encoding(console_out)" if -t STDOUT; binmode STDERR, ":encoding(console_out)" if -t STDERR;
>>>>    STDIN/STDOUT  /    utf8  ...
>>>>
>>>>  ,
>>>>   .
>>>>
>>>> Mon, 22 Sep 2014 01:28:15 +0400  Nikolay Mishin <mi  ya.ru>:
>>>>> , MoscowPM,
>>>>>     win7 (    ,  )
>>>>>
>>>>> #!/usr/bin/env perl
>>>>> use utf8;
>>>>> use Modern::Perl;
>>>>> use Encode::Locale;
>>>>> use Encode qw( decode encode from_to);
>>>>> use Text::Iconv;
>>>>> use Encode::Detect::Detector;
>>>>> use Data::Dumper qw( Dumper );
>>>>>
>>>>> if (-t)
>>>>> {
>>>>> binmode(STDIN, ":encoding(console_in)");
>>>>> binmode(STDOUT, ":encoding(console_out)");
>>>>> binmode(STDERR, ":encoding(console_out)");
>>>>> }
>>>>>
>>>>> my $lang = shift or die "Usage: $0 What_is_your_language?\n";
>>>>> my_dump('lang_01',$lang);
>>>>> my $converter = Text::Iconv->new( "cp1251", "utf-8");
>>>>> $lang = $converter->convert($lang);
>>>>> my_dump('lang_02',$lang);
>>>>> $lang = Encode::decode("utf8",$lang);
>>>>> my_dump('lang_03',$lang);
>>>>> my_dump('lang_04_',qq{});
>>>>>
>>>>> $lang =~ /(perl|) (?{print "use Perl or die!!\n   !!";}) /ix;#  , ?
>>>>>
>>>>> sub my_dump
>>>>> {
>>>>> my ($name,$var)=@_;
>>>>> local $Data::Dumper::Useqq = 1;
>>>>> local $Data::Dumper::Indent = 0;
>>>>> local $Data::Dumper::Terse = 1;
>>>>> print(Encode::Detect::Detector::detect(qq{$lang})." ".qq{\$$name }." dump=".Dumper($var)."\n");
>>>>> }
>>>>>
>>>>>     
>>>>> https://github.com/mishin/presentation/blob/master/100_regex_4_moscow_pm.pl
>>>>>
>>>>>   ,  
>>>>> perl 100_regex_4_moscow_pm.pl 
>>>>>     ""      
>>>>>
>>>>> :
>>>>> 1) ,   
>>>>> perl -MEncode::Detect::Detector -E "say Encode::Detect::Detector::detect(qq{})"
>>>>>    ISO-8859-7
>>>>> my $converter = Text::Iconv->new( "cp1251", "utf-8");
>>>>> Text::Iconv    cp1251 ( ISO   ) ?
>>>>>
>>>>> 2)    
>>>>> UTF-8 $lang_02 dump="\320\277\320\265\321\200\320\273"
>>>>> $lang = Encode::decode("utf8",$lang);
>>>>> UTF-8 $lang_03 dump="\x{43f}\x{435}\x{440}\x{43b}"
>>>>> --   decode?
>>>>>    -   utf8,   
>>>>>
>>>>> ,  !!
>>>>>
>>>>> --
>>>>>  
>>>>>  
>>>>>
>>>>> --
>>>>> Moscow.pm mailing list
>>>>> moscow-pm  pm.org | http://moscow.pm.org
>>>> ,
>>>>
>>>> --
>>>> Moscow.pm mailing list
>>>> moscow-pm  pm.org | http://moscow.pm.org
>>> --
>>>  
>>>  
>>> --
>>> Moscow.pm mailing list
>>> moscow-pm  pm.org | http://moscow.pm.org
>> ,
>>
>> --
>> Moscow.pm mailing list
>> moscow-pm  pm.org | http://moscow.pm.org
>
> --
>  
>  
>
> --
> Moscow.pm mailing list
> moscow-pm  pm.org | http://moscow.pm.org

-- 
 
 



Moscow-pm