in reply to Re: How do I use grep in a script
in thread How do I use grep in a script

The OP wants to do it in Perl. I'm afraid it is somewhat counterproductive to suggest shelling out of Perl with backticks or qx//.

Replies are listed 'Best First'.
Re^3: How do I use grep in a script
by ForgotPasswordAgain (Vicar) on Dec 27, 2017 at 17:17 UTC
    Though there's value in learning how to do it in Perl, I respectfully disagree about the "counterproductive" part. The one-liner being done, just wrap backticks around it, use a split /\n/, and that's that (unless there are other constraints). I wouldn't be surprised if it were also faster, though that depends and might not matter.
      It is usually a recommended good practice not to shell out to the system when you can avoid it. And there are many good reasons for that, security and portability just to name a few. I think it should be avoided especially when the commands you want to run exists in core Perl.

      See, for example, Calling External Commands More Safely and The problem of "the" default shell.

        I don't need a lecture. You cited more things irrelevant to this problem: "Good practice", Security, Portability (previously "counterproductive"). My answer was perfectly fine in context.