此呼叫
my $th = threads->create(\&print, "Hello thread World!\n");
$th->join();工作正常。但是一旦我添加了
binmode(STDOUT, ":encoding(ISO-8859-1)");对于我的脚本文件,我得到一个错误,如“分段错误”,“访问被拒绝”。
在尝试调用perl线程时定义编码类型有什么错?
示例:
use strict; use warnings;
use threads;
binmode(STDOUT, ":encoding(ISO-8859-1)");
my $th = threads->create(\&print, "Hello thread World!\n");
$th->join();
sub print {
print @_;
}这段代码对我不起作用。
亲切的问候
--安迪
发布于 2010-04-15 22:08:23
这被报告为bug in Perl's bug tracker。我在Windows5.12 RC0上也遇到了同样的故障。
发布于 2012-10-15 23:07:43
#!/usr/bin/perl
use strict; use warnings; use threads;
open my $fh, '>>', '/tmp/1' or die $!;
binmode $fh, ':encoding(isolatin1)' or die $!; # LINE 'A'
my $t = threads->create(sub { sleep 1; }); # LINE 'B'
$t->join();以上是Perl 5.12.4中'B‘行的段错误。如果您交换行'A‘和'B',代码运行良好。如果在创建线程之前关闭$fh,它也运行得很好。因此,在这个问题得到解决之前,只要确保在创建新线程时没有打开任何已绑定编码的文件句柄即可。
https://stackoverflow.com/questions/2644238
复制相似问题