Why do I get a segmentation error when I use binmode with streams in Perl?

this challenge

my $th = threads->create(\&print, "Hello thread World!\n");
$th->join();

works great. But as soon as I add

binmode(STDOUT, ":encoding(ISO-8859-1)");

in my script file, I get the error "segmentation fault", "access denied".

What is wrong to determine the type of encoding when trying to call a perl stream?

Example:

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 @_;
}

This code does not work for me.

Yours faithfully

- Andy

+3
source share
3 answers

This is reported as an error in tracking Perl errors . I have the same crash on 5.12 RC0 on Windows.

+3
source

-, , print , , , ( perl , ).

-, :

#!/usr/bin/perl

use strict; use warnings;
use threads;

my $th = threads->create(\&print, "Hello thread World!\n");
$th->join();

sub print {
    binmode(STDOUT, ":encoding(ISO-8859-1)");
    print @_;
}

:

C:\Temp> t
Hello thread World!

, STDOUT , - .

, script, , , , , .

+3
#!/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();

segfaults Perl 5.12.4 "B". "A" "B", . , $fh, . , , , , , .

+2
source

Source: https://habr.com/ru/post/1741248/


All Articles