I noticed that a patch recently submitted for Koha adds the following line to one of Koha’s Perl modules:
use utf8;
utf8
is a perfectly fine and proper Perl pragma, right? Indeed it is. The problem is that the purpose of the patch is to try to fix an issue with reading and displaying UTF-8 characters from a file. So what does use utf8;
contribute to that patch?
Nothing.
The only thing that the utf8
pragma does is signal to the Perl interpreter that the Perl source code is in UTF-8. If you’re using non-ASCII characters in your source code, you’ll need the pragma. For example,
use utf8;
my $str = "La lluvia en España se mantiene principalmente en el llano!";
or even
use utf8;
my $str_en_inglés = "The rain in Spain falls mostly on the plain!";
If what you’re actually trying to do is ensure that the script is handling UTF-8 input and output correctly, use utf8;
won’t help. This tutorial will.
A pragma that does less than you might think by Galen Charlton is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
A rookie mistake. If only it were *that* easy.