in reply to Re^2: strange utf-8 (I think) behaviour...
in thread strange utf-8 (I think) behaviour...

Now, I remember reading somewhere that decoding in Perl was actually the same as encoding in utf-8
Not true.
use strict; use warnings; use utf8; use Encode qw(encode_utf8); binmode STDOUT, ':encoding(UTF-8)'; my $s = "sämple\n"; print uc $s; print uc encode_utf8($s); __END__ Output: SÄMPLE SäMPLE

Note that the use utf8; implicitly decodes string constants in this program.

is it as simple as decoding each element individually before using it?

Yes.

Would I then need to re-encode it or should setting the charset in the content type for the email be sufficient?

You should give your decoded string to a module that does the encoding for you. No need to re-invent the wheel.

Replies are listed 'Best First'.
Re^4: strange utf-8 (I think) behaviour...
by seekay (Initiate) on Oct 24, 2008 at 02:11 UTC

    Thanks again Moritz.

    I've installed Mail::Lite and tried to add a new subroutine to send a mail alongside my existing one.

    I've had a couple of problems doing this as, as I mentioned above, I am completely new to Perl.

    I believe I have overcome most of those issues, as there are no more compilation or errors or errors relating directly to my code, but now I have the following error :
    Wide character in syswrite at /usr/lib/perl5/5.8.8/Net/Cmd.pm line 436.

    Does that look like something I've done wrong in my implementation of the MIME::Lite code or something in the installation of the module even? Any ideas at all?

    Thanks in advance for any trouble taken...

    P.S.As aside, I'd really like to get to the bottom of the original problem too, I'm not sure it is due to a mixture of utf8/non-utf8 strings as I'm sure the results coming in from the DB are utf-8 as they are all encoded correctly in the mail headers, also, the additional information I outputted into the mail shows that both the string with the problem and the string it is being replaced in are both utf-8, if you have any ideas on this that would be great too!