views:

902

answers:

4

Hi there,

I'm modifying a mature CGI application written in Perl and the question of content encoding has come up. The browser reports that the content is iso-8859-1 encoded and the application is declaring iso-8859-1 as the charset in the HTTP headers but doesn't ever seem to actually do the encoding. None of the various encoding techniques described in the perldoc tutorials (Encode, Encoding, Open) are used in the code so I'm a little confused as to how the document is actually being encoded.

As mentioned, the application is quite mature and likely predates many of the current encoding methods. Does anyone know of any legacy or deprecated techniques I should be looking for? To what encoding does Perl assume/default to when no direction is provided by the developer?

Thanks

A: 

If the browser reports the content as iso-8859-1, maybe your Perl script didn't output the correct headers to specify the charset?

Sec
hmm, I forgot to mention that when the app is building the page, it is specifying the content-encoding as iso-8859-1 in the http headers. I better update the question...
kierse
the browser assumes the charset in the http header is correct, so if you want to output utf-8 you should also specify utf-8.
Sec
+1  A: 

Perl will not assume anything, but the browser is assuming that encoding based usually on guesswork. The documents are output directly, just as they were written, if none of the encoding techniques is used.

You can specify the charset in the HTTP Content-Type header.

Vinko Vrsalovic
+8  A: 

By default Perl handles strings as being byte sequences, so if you read from a file, and print that to STDOUT, it will produce the same byte sequence. If your templates are Latin-1, your output will also be Latin-1.

If you use a string in text string context (like with uc, lc and so on) perl assumes Latin-1 semantics, unless the string has been decoded before.

More on Perl, charsets and encodings

moritz
+1  A: 

The first place I'd look is the server configuration. If you aren't setting the content-encoding header in the program, you're likely picking up the server's guess.

Run the script separate from the server to see what its actual output is. When the server gets the output from a CGI program (that's not nph), the server fixes up the header for anything it thinks is missing before it sends it to the client.

brian d foy