我在 perl 文件中有以下代码。此命令的目的是在 file.txt.system(\' find . -type f -name file.txt | xargs sed -i -e \'$ ... 的末尾添加一行 \'- - test 0\'
我在 perl 文件中有以下代码。此命令的目的是在 file.txt 末尾添加一行 \'- - test 0\'。
system(" find . -type f -name file.txt | xargs sed -i -e "$ a- - test 0" ");
当我尝试运行脚本时,出现如下所示的错误。
Scalar found where operator expected at timeStampConfig.pl line 24, near "" find . -type f -name file.txt | xargs sed -i -e "$ a"
(Missing operator before $ a?)
Number found where operator expected at timeStampConfig.pl line 24, near "test 0"
(Do you need to predeclare test?)
String found where operator expected at timeStampConfig.pl line 24, near "0" ""
(Missing operator before " "?)
syntax error at timeStampConfig.pl line 24, near "" find . -type f -name file.txt | xargs sed -i -e "$ a"
Execution of timeStampConfig.pl aborted due to compilation errors.
我尝试从命令提示符执行下面的行并且运行良好。
find . -type f -name file.txt | xargs sed -i -e '$ a- - test 0'
我也尝试使用单引号,如下所示,但最终出现错误。
system("find . -type f -name file.txt | xargs sed -i -e '$ a- - test 0'");
sed: -e expression #1, char 1: unknown command: `-'
我是 perl 新手,需要一些帮助。
使用 5.016;sub foo(){说\'foo\';}sub main(){foo(42);}main();如果我运行上面的代码,它将显示下面的错误,这是我所期望的,因为 foo 没有参数......
use 5.016;
sub foo() {
say "foo";
}
sub main() {
foo(42);
}
main();
如果我运行上面的代码,它将显示 错误 ,这是我所期望的,因为 foo
它没有参数:
Too many arguments for main::foo at b.pl line 8, near "42)"
Execution of b.pl aborted due to compilation errors.
use 5.016;
sub main() {
foo(42);
}
sub foo() {
say "foo";
}
main()
但如果我运行上面的代码,它可以 正确 :
foo
为什么 foo
这次要接受参数?