[EDIT: It turns out that the original version of this question contained two different issues masquerading as one. (I realized this only after reading and working through tripleee's comment.) Therefore, I split the original question into two. I edited this post to include the issue I figured out thanks to tripleee's comment, and posted the second one here. BTW, that second post incorporates the fix I came with to the problem described in this post, namely setting STDOUT
's encoding explicitly within the script, using binmode
.]
I'll use the short demo script below to illustrate the problem.
# -*- coding: utf-8 -*-
use strict;
use feature 'unicode_strings';
use POSIX 'locale_h';
use locale;
use utf8;
setlocale( LC_CTYPE, 'de_DE.UTF-8' );
my $non_ascii = 'ßäöüÄÖÜ';
print "$non_ascii\n";
my @non_ascii = split //, $non_ascii;
print "$_\n" for @non_ascii;
$DB::single = 1; 1; # return control to DB
(The last line is effectively a breakpoint.)
OK, now I run this under the Perl debugger:
% perl -C -d dbtest.pl
Loading DB routines from perl5db.pl version 1.37
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(dbtest.pl:8): setlocale( LC_CTYPE, 'de_DE.UTF-8' );
DB<1> c
ßäöüÄÖÜ
ß
ä
ö
ü
Ä
Ö
Ü
main::(dbtest.pl:17): $DB::single = 1; 1; # return control to DB
DB<1>
So far so good: the script produced the expected output, and now the debugger has entered into single-step mode, and is waiting for input.
If I now just restart the debugger with R
, and run the script again (with c
, exactly as before), this is what happens:
DB<1> R
Warning: some settings and command-line options may be lost!
Loading DB routines from perl5db.pl version 1.37
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(dbtest.pl:8): setlocale( LC_CTYPE, 'de_DE.UTF-8' );
DB<1> c
\337\344\366\374\304\326\334
\337
\344
\366
\374
\304
\326
\334
main::(dbtest.pl:17): $DB::single = 1; 1; # return control to DB
DB<1>
Furthermore, now print
no longer produces human-readable output:
DB<1> print $non_ascii
\337\344\366\374\304\326\334
How can keep the output looking human-readable after a restart?