in reply to Re^5: FCGI, tied handles and wide characters
in thread FCGI, tied handles and wide characters
Like most things Perl it's an embarrassing historical artifact, I cut'n'pasted from my usual file slurping routine which at a sprightly 50 lines was too big to fit in the SSCCE and didn't really think about it. Speaking of not thinking things through is there anything really wrong with the following SSCCE which accomplishes my original goal of bypassing perlio completely and using _utf8_on? Apart from the fact taint doesn't like it it seems like it would really speed up working on files that I know are utf-8.
use utf8;
use Encode qw(_utf8_on);
my $file = 'test_utf8';
binmode STDOUT, ':encoding(UTF-8)';
my $line = &sysfileread($file);
_utf8_on($line);
if ($line =~ /(❇)/) { print "found '$1'\n"; }
print $line;
sub sysfileread {
my ($file) = @_;
my $string;
open(my $fh, "<", $file) || die "Can't open $file for reading: $!";
my $size_left = -s $fh;
while( $size_left > 0 ) {
my $read_cnt = sysread($fh, $string, $size_left, length $string);
last unless( $read_cnt );
$size_left -= $read_cnt;
}
return $string;
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: FCGI, tied handles and wide characters
by hippo (Archbishop) on Sep 16, 2024 at 13:33 UTC | |
by Maelstrom (Beadle) on Sep 21, 2024 at 09:46 UTC | |
by ikegami (Patriarch) on Sep 21, 2024 at 16:16 UTC | |
|
Re^7: FCGI, tied handles and wide characters
by NERDVANA (Priest) on Sep 17, 2024 at 01:40 UTC |