当使用binmode时,我是否应该从以前可能使用的binmode中弹出层?
#!/usr/bin/env perl
use warnings;
use 5.012;
use autodie;
open my $tty, '>:encoding(utf8)', '/dev/tty'; # ...
close $tty;
open $tty, '>:encoding(latin1)', '/dev/tty'; # ...
close $tty;
open $tty, '>:encoding(utf8)', '/dev/tty'; # ...
close $tty;
open $tty, '>:encoding(latin1)', '/dev/tty'; # ...
close $tty;
open $tty, '>:bytes', '/dev/tty';
say "@{[ PerlIO::get_layers( $tty ) ]}"; # unix perlio
close $tty;
say "----------------------------------------";
binmode STDOUT, ':encoding(utf8)'; # ...
binmode STDOUT, ':encoding(latin1)'; # ...
binmode STDOUT, ':encoding(utf8)'; # ...
binmode STDOUT, ':encoding(latin1)'; # ...
binmode STDOUT, ':bytes';
say "@{[ PerlIO::get_layers( *STDOUT ) ]}"; # unix perlio encoding(utf8) /
# utf8 encoding(iso-8859-1) utf8 encoding(utf8) utf8 encoding(iso-8859-1)
binmode STDOUT, ':pop:pop:pop:pop:bytes';
say "@{[ PerlIO::get_layers( *STDOUT ) ]}"; # unix perlio。
#!/usr/bin/env perl
use warnings;
use 5.012;
use autodie;
open my $tty, '>:encoding(utf8)', '/dev/tty'; # ...
close $tty;
open $tty, '>:raw', '/dev/tty';
say "@{[ PerlIO::get_layers( $tty ) ]}"; # unix
close $tty;
say "----------------------------------------";
binmode STDOUT, ':encoding(utf8)'; # ...
binmode STDOUT, ':raw';
say "@{[ PerlIO::get_layers( *STDOUT ) ]}"; # unix perlio
binmode STDOUT, ':pop:raw';
say "@{[ PerlIO::get_layers( *STDOUT ) ]}"; # unix发布于 2011-01-19 00:05:38
弹出真实图层时需要使用:pop,例如:encoding(...)。所以,是的,如果你想用一个真实的层替换另一个层,那么你必须使用:pop。
但请注意,按下:raw实际上会导致一系列的弹出...:perlio会自动在下面插入:unix。因此,pops的确切数量实际上取决于当前层。
正如documentation自己所说的:
需要更优雅(更安全)的界面。
https://stackoverflow.com/questions/4689325
复制相似问题