Perl脚本中的Shell命令

时间:2014-09-26 09:38:03

标签: regex perl unix grep

所有

我有以下shell命令在shell上按预期工作但在perl

中调用时不工作

Shell命令:

grep -P -s -irl --include \*.v "\s+hello\s?[(].*" <PATH> 

工作正常

Perl:

$inst_search = `grep -P -s -irl --include \*.v "\s+$inst\s?[(].*" @plt_dirs`;

不工作

我怀疑我在grep中错过了regexp的内容..请更正我!

谢谢, 的Vivek

2 个答案:

答案 0 :(得分:0)

试试这个:

$inst_search = qx#grep -P -s -irl --include \*.v "\s+$inst\s?[(].*" @plt_dirs#;

或使用任何其他非字母数字字符代替"#"进行引用。

答案 1 :(得分:0)

当用字符串调用exec / system / qx(或反引号)时,Perl将转义特殊的shell字符。

尝试使用exec或系统函数,但传递一个列表,例如

system('grep', '-P', '-s', '-irl', '--include', '\*.v', '"\s+hello\s?[(].*"', @plt_dirs);

您可能还想查看一个为您执行某些错误处理的模块,例如IPC :: System :: Simple。