【发布时间】:2018-02-12 22:47:08
【问题描述】:
有什么方法可以在 Perl 中从 foo1.pl 执行 foo2.pl,并将 foo2.txt 附加到 foo1.txt 然后创建 foo3.txt?谢谢。
即
foo1.pl
print "Hello"; # output to foo1.txt;
foo2.pl
print "World"; # output to foo2.txt;
如何基于foo1.pl创建foo3.txt文件。
foo3.txt
Hello
World
类似于将 foo2.txt 附加到 foo1.txt。
据我所知,我可以打开 foo1.txt 和 foo2.txt,然后将这些行包含在 foo3.pl 中。 p>
print FOO3_TXT (<FOO1_TXT>);
print FOO3_TXT (<FOO2_TXT>);
有什么好的方法吗?
更新我的测试 (ActivePerl 5.10.1)
我的 foo.pl
#!C:\Perl\bin\perl.exe
use strict;
use warnings;
print "world\n";
我的hw.pl(foo.pl和hw.pl在同一目录)
#!C:\Perl\bin\perl.exe
use strict;
use warnings;
print 'hello ';
print `./foo.pl`;
输出
**D:\learning\perl>hw.pl
你好'。'不被识别为内部或外部命令, 可运行的程序或批处理文件。**
如果 hw.pl 更新 {}:
#!C:\Perl\bin\perl.exe
use strict;
use warnings;
print q{hello }, qx{./foo.pl};
现在输出。 (hello的位置略有不同)
D:\learning\perl>hw.pl '。'不被识别为内部或外部命令, 可运行的程序或批处理文件。 你好
[更新]。
已修复。看答案,
【问题讨论】:
-
回复:您的更新 - 请参阅我在回答中的最后一条评论。