我试图在perl版本5.8.8中模拟backticks操作符。据我所理解,在perl版本5.8.8中不可能模拟它。但是在perl版本5.9中,我可以轻松地使用
*CORE::GLOBAL::readpipe = \&mock_readpipe
有没有办法在perl版本5.8.8中模拟backticks操作符。我能够模拟system(),但不能模仿回退。
发布于 2015-09-09 06:29:15
您可以重写system()和read管道(),因为它们是二等关键字(overridable)。在Perl5.8中,您不能覆盖qx//或
, even though they use the same underlying code as readpipe(), simply because they are first-class (non-overridable) keywords. See perl\_keywords.pl and opcode.pl in the Perl source code. Why are some keywords not overridable? The main reason is that those keywords are used as part of some further parsing magic, i.e. they don't follow the usual function call style parsing. The good news is that change [**#29168**](http://www.nntp.perl.org/group/perl.perl5.changes/2006/10/msg16994.html) to perl made qx// overridable. Hooray! That was released in Perl 5.9.5, and will eventually make it to a maintenance release as Perl 5.10.1. When that happens, setting \*CORE::GLOBAL::readpipe will override readpipe(), qx// and。
阅读关于僧侣的完整讨论:模拟或捕获系统调用
还可以查看IPC::System::Simple。
https://stackoverflow.com/questions/32471994
复制相似问题