| "; unless ($exit) { my $first_query = < DOC my $second_query = < DOC my $req = HTTP::Request -> new ( POST => 'http://xmlsearch.yandex.ru/xmlsearch'); $req -> content_type ('application/x-www-form-urlencoded'); $req -> content ($first_query); my $response = $ua -> request ($req); $first_xml = $response -> content; my $first_query_success = $response -> is_success; if ($first_query_success) { $first_xml = XML::XPath -> new ( xml => $first_xml ); my $error_code = $first_xml -> findvalue ('/yandexsearch/response/error/@code'); my $error = $first_xml -> findvalue ('/yandexsearch/response/error'); if ("$error_code" eq '0') { $first_word_matches = "$error_code"; } elsif ("$error") { print "$error: $first_word и $user_word \n"; #$exit = 1; } } else { warn "response from server not succeed\ndetails: " . $response -> {'code'} . " " . $response -> {'message'}; } $req -> content ($second_query); $response = $ua -> request ($req); $second_xml = $response -> content; my $second_query_success = $response -> is_success; if ($second_query_success) { $second_xml = XML::XPath -> new ( xml => $second_xml ); my $error_code = $second_xml -> findvalue ('/yandexsearch/response/error/@code'); my $error = $second_xml -> findvalue ('/yandexsearch/response/error'); if ("$error_code" eq '0') { $second_word_matches = "$error_code"; } elsif ("$error") { print "$error: $second_word и $user_word \n"; #$exit = 1; } } else { warn "response from server not succeed\ndetails: " . $response -> {'code'} . " " . $response -> {'message'}; print "Внутренняя ошибка сервера\n"; $exit = 1; } } if ($exit) { print < подобрать третье слово, которое с одним из слов данной пары встречается намного чаще, чем с другим, т.е. наиболее «контрастное». При подсчете очков учитываются только INTRO } else { if ($mode eq 'by server') { $first_word_matches = $first_xml -> findvalue ('/yandexsearch/response/results/grouping/found[@priority = "strict"]/text()') unless defined $first_word_matches; $second_word_matches = $second_xml -> findvalue ('/yandexsearch/response/results/grouping/found[@priority = "strict"]/text()') unless defined $second_word_matches; } elsif ($mode eq 'by page') { $first_word_matches = $first_xml -> findvalue ('/yandexsearch/response/found[@priority = "strict"]/text()') unless defined $first_word_matches; $second_word_matches = $second_xml -> findvalue ('/yandexsearch/response/found[@priority = "strict"]/text()') unless defined $second_word_matches; } if (defined $first_word_matches and int $first_word_matches > 0) { print "$first_word и $user_word: найдено $first_word_matches словосочетаний \n" }; if (defined $second_word_matches and int $second_word_matches > 0) { print "$second_word и $user_word: найдено $second_word_matches словосочетаний \n" }; print < |
| |||||||||