in reply to Wide character in subroutine entry using encode_qp

encode_qp expects encoded text ("the quoted-printable encoding is only defined for single-byte characters").

use Encode qw( encode_utf8 ); my $encoded = encode_qp(encode_utf8($str));

$ cat a.pl use strict; use warnings; use feature qw( say ); use utf8; use open ':std', ':encoding(UTF-8)'; use Encode qw( encode_utf8 ); use MIME::QuotedPrint qw( encode_qp ); for my $str ( "a\x{201E}z", "a„z", "a\x{201C}z", "a\x{03C9}z", "aäz", ) { say $str; my $str_q; if (!eval { $str_q = encode_qp($ARGV[0] ? encode_utf8($str) : $str); return 1; }) { warn($@); next; } print $str_q; }
$ perl a.pl 0
a„z
Wide character in subroutine entry at a.pl line 22.
a„z
Wide character in subroutine entry at a.pl line 22.
a“z
Wide character in subroutine entry at a.pl line 22.
aωz
Wide character in subroutine entry at a.pl line 22.
aäz
a=E4z=
$ perl a.pl 1
a„z
a=E2=80=9Ez=
a„z
a=E2=80=9Ez=
a“z
a=E2=80=9Cz=
aωz
a=CF=89z=
aäz
a=C3=A4z=

Note that "aäz" didn't actually work; Perl was just unable to automatically detect the error.

Replies are listed 'Best First'.
Re^2: Wide character in subroutine entry using encode_qp
by rumburak (Initiate) on Jun 23, 2017 at 18:32 UTC
    Thanks for such a good explanation! I am impressed!