Perl6:如何读取STDIN原始数据?

时间:2016-01-20 07:07:49

标签: encoding stdin perl6

我怎么能在Perl6中编写这个Perl5代码?

var res = col1.Where(q => !col2.Contains(q))

评论cuonglm的答案。

我已经在使用my $return = binmode STDIN, ':raw'; if ( $return ) { print "\e[?1003h"; }

read

但是当STDIN设置为UTF-8时,我会在my $termios := Term::termios.new(fd => 1).getattr; $termios.makeraw; $termios.setattr(:DRAIN); sub ReadKey { return $*IN.read( 1 ).decode(); } sub mouse_action { my $c1 = ReadKey(); return if ! $c1.defined; if $c1 eq "\e" { my $c2 = ReadKey(); return if ! $c2.defined; if $c2 eq '[' { my $c3 = ReadKey(); if $c3 eq 'M' { my $event_type = ReadKey().ord - 32; my $x = ReadKey().ord - 32; my $y = ReadKey().ord - 32; return [ $event_type, $x, $y ]; } } } } $x大于127 - 32的情况下出错:

$y

1 个答案:

答案 0 :(得分:5)

您可以使用method read()中的class IO::Handle执行二进制读取:

#!/usr/local/bin/perl6

use v6;

my $result = $*IN.read(512);
$*OUT.write($result);

然后:

$ printf '1\0a\n' | perl6 test.p6 | od -t x1
0000000 31 00 61 0a
0000004

你不需要在Perl 6中使用 binmode ,因为当你决定以二进制或文本的形式读取数据时,取决于你使用的方法。