Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^8: Correct Perl settings for sending zipfile to browser

by Anonymous Monk
on Nov 17, 2019 at 22:01 UTC ( [id://11108836]=note: print w/replies, xml ) Need Help??


in reply to Re^7: Correct Perl settings for sending zipfile to browser
in thread Correct Perl settings for sending zipfile to browser

Adding the "use open qw/:std :utf8/;" pragma did not remove the useless warning. It shouldn't, if I understand things correctly. That is because the source of the "wide characters" is embedded in the code itself, and is not brought in from an external file which must be opened. I am unaware of a way to encode the source code itself, or to decode it, save for the "use utf8;" pragma within the code itself. I have tested the code both with and without those characters in that HTML header, and removing them is the only way to erase the error message. I'm not willing to do that, because I want that heading. I suppose I should really just add a "no warnings;" to the code, the opposite of "use warnings;". That would silence the false alarm.

To be honest, in this day and age, having UTF8 characters in the code should be a complete non-issue. The "use utf8;" pragma should be unnecessary. It should be the built-in default. Ditto with the open pragma.

It may be worth noting that I have already required UTF8 for the HTML form, and have specified it in the output, i.e.:

<HTML lang="utf8"> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf8">

Replies are listed 'Best First'.
Re^9: Correct Perl settings for sending zipfile to browser
by haukex (Archbishop) on Nov 17, 2019 at 22:23 UTC
    That is because the source of the "wide characters" is embedded in the code itself, and is not brought in from an external file which must be opened.

    The source of the warnings is most likely that some string in your Perl program contains Unicode characters that you are trying to output through a stream that is not set to the proper encoding. Those characters can get there in a number of different ways: a file, a value submitted on an HTML form, from the database, or a Perl string such as the one I showed above - no use utf8 necessary.

    That would silence the false alarm.

    It's not a false alarm - something really is wrong. It may seem to work for now, but it's possible that if a user with a browser different from yours visits your site, things may break in mysterious ways.

    Adding the "use open qw/:std :utf8/;" pragma did not remove the useless warning.

    That could mean that it's some other output stream, or possibly that some module reset STDOUT back to the default, and you might have to do an e.g. binmode STDOUT, ':raw:encoding(UTF-8)'; at runtime.

    I have tested the code both with and without those characters in that HTML header, and removing them is the only way to erase the error message.

    As I said, a SSCCE would be helpful in demonstrating that to us, if you'd like help with that.

    The "use utf8;" pragma should be unnecessary. It should be the built-in default.

    Yes, that's certainly a very valid argument, and one that others have raised. Perl has a long history of backwards-compatibility though, so (unfortunately) it's unlikely to be changed.

    It may be worth noting that I have already required UTF8 for the HTML form, and have specified it in the output

    Yes, that's good (except utf8 is not a valid lang, it should probably be en or whatever language your page is in). You could also specify it in the HTTP headers (e.g. by supplying -charset=>'UTF-8' to CGI::Simple's header method).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11108836]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2024-04-25 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found