Really glad to see you now have a working SSCCE. I'm somewhat bemused by the use of scalar ref for the string in the subroutine - can you elaborate on why that is desired or necessary?
There should be no problem with using Encode::decode() to do the decoding, and that is often what I use. Since you put the effort in to provide your SSCCE, here is mine in return, using this sub.
use strict;
use warnings;
use utf8;
use Encode qw/decode/; # For explicit decoding only
binmode STDOUT, ':encoding(UTF-8)';
my $file = 'test_utf8';
print "Explicitly decoded:\n";
my $encoded_text = fileread ($file, ':raw');
my $text = decode ('UTF-8', $encoded_text, Encode::FB_CROAK);
if ($text =~ /(❇)/) { print "found '$1'\n"; }
print $text;
print "\n\nImplicitly decoded:\n";
$text = fileread ($file, ':encoding(UTF-8)');
if ($text =~ /(❇)/) { print "found '$1'\n"; }
print $text;
sub fileread {
my ($file,$enc) = @_;
open my $fh, "< $enc", $file or die "Can't open $file: $!";
local $/;
my $string = <$fh>;
close $fh;
return $string;
}
As is hopefully clear, this shows that the same result occurs whether by having the PerlIO layer perform the decoding implicitly or by performing it explicitly with Encode::decode() in the code (as you would need to do in order to process your FCGI parameters, for example). I have simplified fileread() to remove the apparently unnecessary scalar ref too.
I notice all the occurrences of ❇ in my code blocks have been turned into ❇
Yes, it is a known issue and is an unfortunate consequence of this site pre-dating much of unicode handling. If you have utf-8 characters in your source you can use <pre> tags as I have here.
🦛
In reply to Re^5: FCGI, tied handles and wide characters
by hippo
in thread FCGI, tied handles and wide characters
by Maelstrom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |