perl:这里是反引号运算符内的文档
给定一个程序实用程序,它从标准输入获取命令并返回有用的退出代码,这个 perl 语法可以工作:
my $result = `utility -switch1 -switch2 <<HERE
set ridin_round_the_world TRUE;
do this;
sign that;
try {
make some_girl;
return 0;
}
except {
sleep --week;
exit 1;
}
HERE`;
print "result is $result\n";
“有效”,我的意思是 perl 脚本启动该实用程序,在命令列表中进行管道传输,等待直到该实用程序退出并返回结果。
但为什么它有效呢?反引号如何知道调用程序,然后通过管道传入 HERE 文档?我只是幸运地实现了 Perl,还是这是标准行为?
Given a program utility that takes commands from stdin and returns a useful exit code, this perl syntax works:
my $result = `utility -switch1 -switch2 <<HERE
set ridin_round_the_world TRUE;
do this;
sign that;
try {
make some_girl;
return 0;
}
except {
sleep --week;
exit 1;
}
HERE`;
print "result is $result\n";
By "works," I mean the perl script launches the utility, pipes in the command list, waits until the utility exits, and returns the result.
But why does it work? How does backtick know to invoke the program, then pipe in the HERE document? Am I just lucky with my perl implementation, or is this standard behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 shell 的here-doc,而不是 Perl 的。尝试在 shell 中运行:
It's shell's here-doc, not Perl's one. Try running in the shell: