@
@
@specblog2016-08-22 15:58:42
Perl
@specblog, 2016-08-22 15:58:42

How to teach Perl script to work in UTF8?

f75c39c22279498382430a0880f0986d.png
this is the result of incorrect work with the encoding of my script.
index.html:

<!DOCTYPE html>
<html lang="ru">

<head>
  <meta charset="utf-8" />
  <title>Поиск по группе РОСА ВКонтакте</title>
  <meta name="generator" content="Geany 1.28 on GNU/Linux" />
</head>

<body>
  <center>
    <form method="GET" action="/cgi-bin/rosa-search.pl" formenctype="application/x-www-form-urlencoded">
    <h1>Введите поисковый запрос<br />для поиска по группе<br /><a href="https://vk.com/rosalab" target="_blank">«РОСА Линукс» ВКонтакте</a>.</h1>
    <input type="text" name="search_request">
    <input type="hidden" name="search_parametrs" value=" site:vk.com">	
    <!-- пробелы в value стоят специально -->
    <input type="hidden" name="vk_group_name" value=" роса линукс">
    <br /><input type="submit" value="Искать!">
    </form>
  </center>
</body>

</html>

rosa-search.pl:
#!/usr/bin/perl -w
# за основу взято https://www.sitepoint.com/uploading-files-cgi-perl-2/
use strict;
use utf8;
use CGI qw/ :standard -debug /;
# подключаем модуль дл вывода подробных ошибок
use CGI::Carp qw ( fatalsToBrowser );
use File::Basename;
use Text::Iconv;
my $query = new CGI;
# считываем параметры, переданные нам с HTML формы
my $search_request = $query->param("search_request");
my $search_parametrs = $query->param("search_parametrs");
my $vk_group_name = $query->param("vk_group_name");
my $google = "https://www.google.ru/#newwindow=1&q=";
my $string0 = $google.$search_request . $search_parametrs . $vk_group_name;
# print $string0;

print $query->header ( );
# binmode(STDOUT, ":utf8"); 
print <<END_HTML;
<!DOCTYPE html>
<html> 
<head>
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0;URL='$string0'" />
<head>
</html>
END_HTML

How to fix like this. so that the Cyrillic alphabet is processed in the correct encoding?
When run through the console,
$ perl rosa-search.pl
works completely correctly and without bugs.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
parserpro, 2016-09-01
@parserpro

CGI in the 21st century is something.
Get Dancer or Mojolicious, don't do necrophilia.

V
Vladimir, 2016-08-23
@rostel

start by learning the basics

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question