Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How do I use grep in a script

by ForgotPasswordAgain (Priest)
on Dec 26, 2017 at 17:19 UTC ( [id://1206214]=note: print w/replies, xml ) Need Help??


in reply to How do I use grep in a script

I think you're looking for backticks (`...` or qx): Quote Like Operators

Replies are listed 'Best First'.
Re^2: How do I use grep in a script
by Laurent_R (Canon) on Dec 26, 2017 at 20:16 UTC
    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//.
      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1206214]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-03-28 17:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found