我想在Perl脚本中执行下面的一行,以匹配一行与变量的值,owner并type从文件中删除它:
perl -i -ne\"print unless /\b${owner}\b/ and /\b${type}\b/;\" /tmp/test
Run Code Online (Sandbox Code Playgroud)
内容/tmp/test:
node01 A 10.10.10.2
node02 A 10.20.30.1
Run Code Online (Sandbox Code Playgroud)
当我在shell中执行时,这完全正常,但在Perl脚本中也不起作用.
我曾尝试使用反引号,system而且exec.似乎没什么用.
`perl -i -ne\"print unless /\b${owner}\b/ and /\b${type}\b/;\" /tmp/test`
system(q(perl -i -ne\"print unless /\b${owner}\b/ and /\b${type}\b/;\" /tmp/test));
Run Code Online (Sandbox Code Playgroud)
是否可以在Perl脚本中执行Perl一个内衬?
如果是这样,我在这里做错了什么?
注意:我不需要使用sed,grep,awk等从文件中删除一行的解决方案.
perl ×1