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"} );'