基本上,我试图在文本文件中插入一行,并且生成一个系统命令来执行“ perl -pi.orig -e”
这是我想做的事情:
my $find='# Foo Bar'
my $replace="foo/bar/blah.txt\n# Foo'
my $file = './some_text_file.txt'
system("perl -pi.orig -e 's|$find|$replace|;' $file");
Run Code Online (Sandbox Code Playgroud)
这在不使用变量的情况下有效。
$ file中包含以下文本:
# Foo Bar is a comment
then/a/path/to/a/file.txt
Run Code Online (Sandbox Code Playgroud)