Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: quoting for system() and friends

by snoopy (Curate)
on Mar 06, 2007 at 06:18 UTC ( [id://603354]=note: print w/replies, xml ) Need Help??


in reply to quoting for system() and friends

There's a function quotemeta:

To quote from the doco:

Returns the value of EXPR with all non-alphanumeric characters backslashed. (That is, all characters not matching /A-Za-z_0-9/ will be preceded by a backslash in the returned string, regardless of any locale settings.) This is the internal function implementing the \Q escape in double-quoted strings.
Update:

Replies are listed 'Best First'.
Re^2: quoting for system() and friends
by ikegami (Patriarch) on Mar 06, 2007 at 06:36 UTC

    Forgot to check the requirements? quotemeta is useless here.

    $ perl -e '$qs=quotemeta("|"); system( qq{echo "$qs"} );' \|
      If you're constructing SQL statements, you avoid putting quotation marks around a string that allready been formatted with DBI's quote method.

      This is analogous as to how shell arguments constructed using the quotemeta function should be treated, ie:

      $ perl -e '$qs=quotemeta("|"); system( qq{echo $qs} );'

        Ah! Quoted strings were stuck in my mind, probably because we were just talking about them and that's how it's done in Perl.

        perl -e '$qs=quotemeta("|"); eval( qq{print "$qs"} );'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-18 17:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found