谁给解释下这几行代码
时间:2011-06-18
来源:互联网
pipe(FROM_PARENT, TO_CHILD) or die "pipe: $!";
pipe(FROM_CHILD, TO_PARENT) or die "pipe
!";
select((select(TO_CHILD), $| = 1))[0]);
select((select(TO_PARENT), $| = 1))[0]);
pipe(FROM_CHILD, TO_PARENT) or die "pipe

select((select(TO_CHILD), $| = 1))[0]);
select((select(TO_PARENT), $| = 1))[0]);
作者: vgra 发布时间: 2011-06-18
QUOTE:
pipe(FROM_PARENT, TO_CHILD) or die "pipe: $!";
pipe(FROM_CHILD, TO_PARENT) or die "pipe!";
s ...
vgra 发表于 2011-06-18 11:14
pipe(FROM_CHILD, TO_PARENT) or die "pipe!";
s ...
vgra 发表于 2011-06-18 11:14
pipe函数用来建立一对管道:
http://perldoc.perl.org/functions/pipe.html
select那句,表示把对应的句柄的写buffer关闭:
$|
If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; $| tells you only whether you've asked Perl explicitly to flush after each write). STDOUT will typically be line buffered if output is to the terminal and block buffered otherwise. Setting this variable is useful primarily when you are outputting to a pipe or socket, such as when you are running a Perl program under rsh and want to see the output as it's happening. This has no effect on input buffering. See getc for that. See select on how to select the output channel. See also IO::Handle.
If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; $| tells you only whether you've asked Perl explicitly to flush after each write). STDOUT will typically be line buffered if output is to the terminal and block buffered otherwise. Setting this variable is useful primarily when you are outputting to a pipe or socket, such as when you are running a Perl program under rsh and want to see the output as it's happening. This has no effect on input buffering. See getc for that. See select on how to select the output channel. See also IO::Handle.
作者: 兰花仙子 发布时间: 2011-06-18
QUOTE:
select((select(TO_CHILD), $| = 1))[0]);
补充一下,select函数的返回是select之前的旧句柄。
所以上述写法对应于:
- my $old_fh = select TO_CHILD;
- $|=1; # 关闭TO_CHILD的buffer
- select $old_fh;
作者: 兰花仙子 发布时间: 2011-06-18
后面两个纯粹是因为 $| 对应的文件句柄问题。要先切换默认输出文件再设置 $|,然后再把切换回来
作者: zhlong8 发布时间: 2011-06-18
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28