简体   繁体   中英

Unexpected behavior with PerlIO::encoding

When I run this script I get 8 lines of output instead of 2.

#!perl
use strict;
use warnings;
use 5.10.1;

use PerlIO::encoding;
use Encode qw(:fallbacks);
$PerlIO::encoding::fallback = Encode::FB_HTMLCREF;
binmode STDOUT, ":encoding(cp850)";

say "TEST";
say "Hell\x{263a}\x{263b}llo.txt";

Output:

# TEST
# TEST
# Hell☺☻llo.txt
# TEST
# Hell☺☻llo.txt
# TEST
# Hell☺☻llo.txt
#

Why does this script output so many lines?

It's a really old bug: RT#40401 . RT#29720 is probably the same bug, which makes it almost 10 years old. (And that's just when it was reported; I'd guess the bug dates back to when $PerlIO::encoding::fallback was first implemented.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM