Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

utf8 for require scripts

by YarNik (Sexton)
on Dec 23, 2019 at 11:09 UTC ( #11110543=perlquestion: print w/replies, xml ) Need Help??

YarNik has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

In Perl v5.10.1 I did not declare utf8 for require scripts, but in Perl v5.16.3 it is necessary.

What is another solution, do not change a lot of require scripts?

Now my index.pl script looks like this:

#!/usr/bin/perl
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use utf8;
use CGI qw/:standard -utf8 -nosticky/;
use open qw/:utf8/;
binmode(STDOUT, ":utf8");
print header(-type => 'text/html',-charset => 'UTF-8');
print "one один\n";
require "index_req.pl";
print @select;
index_req.pl
#!/usr/bin/perl
@select = qw(one один);
1;
output:
one один one????????
if I add utf8 in index_req.pl
#!/usr/bin/perl
use utf8;
@select = qw(one один);
1;
then output is good:
one один oneодин

Replies are listed 'Best First'.
Re: utf8 for require scripts
by haukex (Chancellor) on Dec 23, 2019 at 13:32 UTC

    A bisect confirms the change is due to the fixing of bug RT#96008 in 639dfab: before v5.16.0, use and require were affected by the open pragma. Since your index_req.pl is apparently encoded in UTF-8, it does require a use utf8; at the top, because that's basically what the utf8 pragma means: "this lexical block is encoded in UTF-8".

    Sorry, but the best practice here is to put the use utf8; pragma at the top of every Perl source file that is encoded in UTF-8, everything else is a hack, or workaround at best.

      I understand, thanks for the explanation.
Re: utf8 for require scripts (updated)
by haukex (Chancellor) on Dec 23, 2019 at 11:25 UTC

    Which of the four instances of utf8 in your sample are you referring to? And could you show some example code that reproduces the problem? Short, Self-Contained, Correct Example

    Update: Thank you for adding some sample code, but see How do I change/delete my post? - please mark your edits as such. Also, did you mean &#1086;&#1076;&#1080;&#1085; or один? On PerlMonks, if you meant the latter, unfortunately it's required to use <pre> instead of <code> tags, which means that HTML/PM special characters like <, >, &, [, and ] need to be escaped too (respectively, &lt;, &gt;, &amp;, &#91;, and &#93;).

      I changed the message, but the block with the code changes Unicode to utf8 by default, so I showed how it looks in the original. Upd. Thank you, I changed it with pre

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11110543]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2020-04-05 02:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (33 votes). Check out past polls.

    Notices?