我用新的样式重写了我的旧代码,如下所示:
#old style
open(FD,"file");
#new style
$fh = IO::File->new("file","r");
Run Code Online (Sandbox Code Playgroud)
文件还可以,但我不知道如何打开管道.
# read from pipes.
open(PIPE,"some_program |");
# write to pipes.
open(PIPE,"| some_program");
Run Code Online (Sandbox Code Playgroud)
如何处理OO Style IO中的管道?
补充:
感谢Jonathan,没关系.
# read from pipes.
$pipe = IO::Pipe->new;
$pipe->reader('some_program');
$data = <$pipe>;
# write from pipes.
$pipe = IO::Pipe->new;
$pipe->writer('some_program');
print $pipe "foo,bar,baz";
Run Code Online (Sandbox Code Playgroud) 我试图从我的Perl程序中运行Bash命令.但是Perl似乎把我的Bash $ PWD环境变量混淆为Perl变量.
我怎么能把它作为一个字符串全部读出来?
这就是我想要运行的
my $path = /first/path;
`ln -s $path $PWD/second/path`
Run Code Online (Sandbox Code Playgroud)
那些反引号在Bash中运行第二行.使用System()会产生同样的问题.
有任何想法吗?