I used in my programs:
use utf8; use encoding 'utf8'; my $out = &refPrint(\%rows);
Earlier, when encoding was working, unicode text from $out was displayed correctly on terminal and on the web.
Now, it dies with an error, that encoding is deprecated
I tried to just use:
use utf8; my $out = &refPrint(\%rows);
I have some Cyrillic text generated in subroutine &refPrint, that returns the result with the html in it, like such:
<table border='1'><tr><td style='vertical-align: top; '>6</td><td><tab +le border='1'><tr><td style='vertical-align: top; '>table_name</td><t +d>reshenia</td></tr> <tr><td style='vertical-align: top; '>description</td><td>&#1056;&#107 +7;&#1096;&#1077;&#1085;&#1080;&#1103;</td></tr> </table></td></tr> <tr><td style='vertical-align: top; '>1</td><td><table border='1'><tr> +<td style='vertical-align: top; '>description</td><td>&#1057;&#1090;& +#1088;&#1091;&#1082;&#1090;&#1091;&#1088;&#1072; &#1090;&#1072;&#1073 +;&#1083;&#1080;&#1094; &#1073;&#1072;&#1079;&#1099; &#1076;&#1072;&#1 +085;&#1085;&#1099;&#1093;</td></tr> <tr><td style='vertical-align: top; '>table_name</td><td>db_structure_ +tables</td></tr> </table></td></tr> <tr><td style='vertical-align: top; '>3</td><td><table border='1'><tr> +<td style='vertical-align: top; '>table_name</td><td>sotrudniki</td>< +/tr> <tr><td style='vertical-align: top; '>description</td><td>&#1057;&#108 +6;&#1090;&#1088;&#1091;&#1076;&#1085;&#1080;&#1082;&#1080;</td></tr> </table></td></tr> <tr><td style='vertical-align: top; '>2</td><td><table border='1'><tr> +<td style='vertical-align: top; '>description</td><td>&#1057;&#1090;& +#1088;&#1091;&#1082;&#1090;&#1091;&#1088;&#1072; &#1087;&#1086;&#1083 +;&#1077;&#1081; &#1074; &#1090;&#1072;&#1073;&#1083;&#1080;&#1094;&#1 +072;&#1093; &#1073;&#1072;&#1079;&#1099; &#1076;&#1072;&#1085;&#1085; +&#1099;&#1093;</td></tr> <tr><td style='vertical-align: top; '>table_name</td><td>db_structure_ +fields</td></tr> </table></td></tr> <tr><td style='vertical-align: top; '>5</td><td><table border='1'><tr> +<td style='vertical-align: top; '>description</td><td>&#1056;&#1072;& +#1081;&#1086;&#1085;&#1099;</td></tr> <tr><td style='vertical-align: top; '>table_name</td><td>rayony</td></ +tr> </table></td></tr> <tr><td style='vertical-align: top; '>4</td><td><table border='1'><tr> +<td style='vertical-align: top; '>description</td><td>&#1047;&#1072;& +#1087;&#1088;&#1086;&#1089;&#1099;</td></tr> <tr><td style='vertical-align: top; '>table_name</td><td>zaprosy</td>< +/tr> </table>
and, if I print it on the terminal, it displays correctly, as in the above example, but if I pass it to the mojolicious template as a placeholder variable, it scrambles, as it i not a utf8, but just a regular bytes, even when I put <meta charset='utf-8' /> tag in html header:
<html><head> <meta charset="utf-8"> </head> <body> &#1054;&#1090;&#1082;&#1088;&#1099;&#1074;&#1072;&#1077;&#1090;&#1089; +&#1103; &#1041;&#1072;&#1079;&#1072;. <table border="1"><tbody><tr><td style="vertical-align: top; ">2</td>< +td><table border="1"><tbody><tr><td style="vertical-align: top; ">tab +le_name</td><td>db_structure_fields</td></tr> <tr><td style="vertical-align: top; ">description</td><td>С&#130;&# +128;&#131;к&#130;&#131;&#128;а полей в &#130;абли&# +134;а&#133; баз&#139; данн&#139;&#133;</td></tr> </tbody></table></td></tr> <tr><td style="vertical-align: top; ">5</td><td><table border="1"><tbo +dy><tr><td style="vertical-align: top; ">table_name</td><td>rayony</t +d></tr> <tr><td style="vertical-align: top; ">description</td><td>&nbsp;ай +н&#139;</td></tr> </tbody></table></td></tr> <tr><td style="vertical-align: top; ">4</td><td><table border="1"><tbo +dy><tr><td style="vertical-align: top; ">table_name</td><td>zaprosy</ +td></tr> <tr><td style="vertical-align: top; ">description</td><td>&#151;ап +&#128;ос&#139;</td></tr> </tbody></table></td></tr> <tr><td style="vertical-align: top; ">1</td><td><table border="1"><tbo +dy><tr><td style="vertical-align: top; ">table_name</td><td>db_struct +ure_tables</td></tr> <tr><td style="vertical-align: top; ">description</td><td>С&#130;&# +128;&#131;к&#130;&#131;&#128;а &#130;абли&#134; баз&# +139; данн&#139;&#133;</td></tr> </tbody></table></td></tr> <tr><td style="vertical-align: top; ">3</td><td><table border="1"><tbo +dy><tr><td style="vertical-align: top; ">description</td><td>Со&#1 +30;&#128;&#131;дники</td></tr> <tr><td style="vertical-align: top; ">table_name</td><td>sotrudniki</t +d></tr> </tbody></table></td></tr> <tr><td style="vertical-align: top; ">6</td><td><table border="1"><tbo +dy><tr><td style="vertical-align: top; ">description</td><td>&nbsp; +&#136;ения</td></tr> <tr><td style="vertical-align: top; ">table_name</td><td>reshenia</td> +</tr> </tbody></table></td></tr> </tbody></table> </body></html>
When I was using encoding pragma, it was working correctly. I tried to copy the output from the terminal and assign it as a string to a variable, then send that variable to the mojolicious template, and it displays correctly. That made me think, that after generating the text in the subroutine, for some reason, it doesn't think, that it's utf8. So, I tried this:
use utf8; use Encode; my $out = decode('UTF-8', &refPrint(\%rows));
This way mojolicious shows the correctly encoded text, but how can I fix this, so that I don't have to explicitly decode the strings, as in the example with the decode function above? How to make it automatic, as it was with the encoding pragma?

In reply to replacement for deprecated encoding pragma by igoryonya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.