Антон, Руслан, спасибо
итог
https://github.com/mishin/gists/blob/master/gtrans2.pl
#use utf8;
#use open qw<:std>;
use open OUT => ':encoding(cp1251)';
&main;
exit;
sub main {
translate_text( $from, $to, $text );
}
sub translate_text {
my ( $from, $to, $words ) = @_;
my $url ="" /> 'http://translate.google.com/translate_t?langpair='
. $from . '|'
. $to
. '&text=' . '+'
. $words;
my $ua = LWP::UserAgent->new;
$ua->agent('');
my $res = $ua->get($url);
die $res->status_line if $res->is_error;
my $html = $res->decoded_content;
my @matches =
$html =~ m{_onmouseout_="this.style.backgroundColor='#fff'">(.*?)</span>}g;
foreach my $translated_string (@matches) {
# my $flag = utf8::is_utf8($translated_string);
# say "[ $flag ]"; $flag==1
utf8::encode($translated_string);
say $translated_string;
}
}
меня удивило, что можно закомментировать use utf8, видимо он где-то есть еще
https://github.com/mishin/gists/blob/master/gtrans2.pl
#use utf8;
#use open qw<:std>;
use open OUT => ':encoding(cp1251)';
&main;
exit;
sub main {
translate_text( $from, $to, $text );
}
sub translate_text {
my ( $from, $to, $words ) = @_;
my $url ="" /> 'http://translate.google.com/translate_t?langpair='
. $from . '|'
. $to
. '&text=' . '+'
. $words;
my $ua = LWP::UserAgent->new;
$ua->agent('');
my $res = $ua->get($url);
die $res->status_line if $res->is_error;
my $html = $res->decoded_content;
my @matches =
$html =~ m{_onmouseout_="this.style.backgroundColor='#fff'">(.*?)</span>}g;
foreach my $translated_string (@matches) {
# my $flag = utf8::is_utf8($translated_string);
# say "[ $flag ]"; $flag==1
utf8::encode($translated_string);
say $translated_string;
}
}
меня удивило, что можно закомментировать use utf8, видимо он где-то есть еще
05.09.2013, 23:24, "Anton Nikishaev" <[email protected]>:On Sep 5, 2013, at 11:14 PM, Nikolay Mishin <[email protected]> wrote:
Руслан, круто, так работает
use utf8;
use open OUT => ':encoding(cp1251)';+use open qw<:std>;
sub translate_text {
my ( $from, $to, $words ) = @_;
my $url ="" /> 'http://translate.google.com/translate_t?langpair='
. $from . '|'
. $to
. '&text=' . '+'
. $words;
my $ua = LWP::UserAgent->new;
$ua->agent('');
my $res = $ua->get($url);
die $res->status_line if $res->is_error;
my $html = $res->decoded_content;
my @matches =
$html =~ m{_onmouseout_="this.style.backgroundColor='#fff'">(.*?)</span>}g;
foreach my $translated_string (@matches) {
say $translated_string;
}
}
https://github.com/mishin/gists/blob/master/gtrans2.pl
но
$./gtrans2.pl --from en --to ru --text "This is a test"
Wide character in say at ./gtrans2.pl line 63.
Это тест
05.09.2013, 22:50, "Ruslan Zakirov" <[email protected]>:->decoded_content и use open OUT => ':encoding(cp1251)';--
Тогда совсем можно не заморачиваться :)
2013/9/5 Anton Nikishaev <[email protected]>
On Sep 5, 2013, at 10:16 PM, Nikolay Mishin <[email protected]> wrote:Encode::from_to( $translated_string, 'koi8', 'cp1251' );Она называется koi8-r
$perl gtrans.pl --from=en --to=ru --text='This is a test'
Unknown encoding 'KOI8' at gtrans.pl line 6305.09.2013, 20:01, "Олег Алексеенков" <[email protected]>:--Nikolay Mishin <[email protected]> писал(а) в своём письме Thu, 05 Sep 2013--
08:38:50 +0400:вопрос, можно ли строкуа почему не работает
Convert::Cyrillic::cstocs( 'KOI8', 'UTF8', $translated_string );
Encode::from_to( $interm_var, 'utf-8', 'cp1251' );
заменить одним преобразованием, чтобы на выходе был win1251?
у меня этого не получилось
Encode::from_to( $interm_var, 'koi8', 'cp1251' );
?
--
Moscow.pm mailing list
[email protected] | http://moscow.pm.org
С уважением
Николай Мишин
--
Moscow.pm mailing list
[email protected] | http://moscow.pm.org
Moscow.pm mailing list
[email protected] | http://moscow.pm.org
--
Best regards, Ruslan.
,
--
Moscow.pm mailing list
[email protected] | http://moscow.pm.org
С уважением
Николай Мишин
--
Moscow.pm mailing list
[email protected] | http://moscow.pm.org,
--
Moscow.pm mailing list
[email protected] | http://moscow.pm.org--С уважениемНиколай Мишин
--
С уважением
Николай Мишин
-- Moscow.pm mailing list [email protected] | http://moscow.pm.org
