morgon has asked for the wisdom of the Perl Monks concerning the following question:
I run CGI::Application::Plugin::TT under mod_perl and need to send either UTF-8 or ISO-8859-1 encoded xml (generated by templates) back to the client.
I have asked about this before but it seems that changing the encoding of STDOUT via binmode does not work under mod_perl.
I have now found a solution that works for me, but it is not entirely clear to me..
What I do is let TT generate the xml in utf8 and then change the encoding in a cgiapp_postrun method like this:
This works but what I don't understand is why it is neccessary to first call decode (it does not work without it).use Encode; sub cgiapp_postrun { my($this, $response_ref)=@_; my $encoding = ... #figure out which encoding to use if($encoding ne "UTF-8") { my $response_utf8 = decode('UTF-8', $$response_ref); $$response_ref = encode('ISO-8859-1', $response_utf8); }
I always thought that by default a Perl-string would be utf8, so I had assumed that I can call encode straight away, but this evidently is wrong...
So can someone please explain what is going on?
Many thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: decode/encode - can someone explain this please
by Anonyrnous Monk (Hermit) on Jan 07, 2011 at 23:02 UTC | |
|
Re: decode/encode - can someone explain this please
by ikegami (Patriarch) on Jan 08, 2011 at 00:04 UTC |