0

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

3
  • Check this ... If this helps you or not : stackoverflow.com/questions/3200801/… Commented Sep 26, 2014 at 9:46
  • Perl has a grep built in. I would suggest using that rather than a shell escape. Commented Sep 26, 2014 at 9:54
  • @Praveen: It's found useful..and solve my problem..Thank you! Commented Sep 28, 2014 at 6:39

2 Answers 2

0

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, e.g.

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.