All
I have following shell command working as per expectation on shell but not working when invoked inside perl
Shell command:
grep -P -s -irl --include \*.v "\s+hello\s?[(].*" <PATH>
working fine
Inside Perl:
$inst_search = `grep -P -s -irl --include \*.v "\s+$inst\s?[(].*" @plt_dirs`;
not working
I am suspecting i am missing something with regexp inside grep..please correct me !
Thanks, Vivek
Try this one:
$inst_search = qx#grep -P -s -irl --include \*.v "\s+$inst\s?[(].*" @plt_dirs#;
Or use any other non-alphanumeric character instead of "#"
for quoting.
Perl will escape special shell characters when calling exec/system/qx (or backticks) with a string.
Try using the exec or system functions, but passing a list, eg
system('grep', '-P', '-s', '-irl', '--include', '\*.v', '"\s+hello\s?[(].*"', @plt_dirs);
You may also want to look at a module that does some of the error handling for you, like IPC::System::Simple.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.