Jason0x21 has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on a perl interface to a sort of database-query program with a command-line interface, and I'm almost at my wits end trying to quote special characters in order to escape them from perl-shell-whatever. An ordinary shell script to do a query might look like this...
eval `script_to_setup_environment`
Report -raw -view fileView -where " \
   fileView.Attr1 in ('eggs') and \
   fileView.Attr2 in ('yes') and \
   fileView.Attr3 in ('blue') \
   " |
...with the pipe going to something else. Now I'm trying to place this script in a "here-document", and having a terrible time with all the double-quotes, single-quotes, newlines, and parentheses, especially since I have to be able to change the values in the single quotes inside the parentheses. Any ideas out there? I'm wearing out my backslash key to no avail. I'd love to do it all inside the perl script if it's possible. Thanks!

Replies are listed 'Best First'.
Re: Save Me from quoting hell?
by lhoward (Vicar) on May 15, 2000 at 19:26 UTC
    I think the String::ShellQute module will do what you need:
    String::ShellQuote - quote strings for passing through the shell. This module contains some functions which are useful for quoting strings which are going to pass through the shell or a shell-like object.
Re: Save Me from quoting hell?
by zodiac (Beadle) on May 15, 2000 at 20:33 UTC
    I understand the skriptpart you posted is a shellscript / stuff-you-enter-on-command-line.
    If that is the case you might want to use xargs and here documents:
    xargs Report -raw -view fileView -where << EOF| pipegoeshere ? "fileView.Attr1 in ('eggs') and fileView.Attr2 in ('yes') and fileVi +ew.Attr3 in ('blue')" ? EOF