in reply to Escaping and quoting ?????

If "$hist_plan_prolog_1" is a table name, and NOT a perl variable, the best bet is to use non-interpolating single quotes, and NOT escape the $.

But the query would be more readable if you used "heredoc" syntax.

here is a sample I use:

my $sql=<<"_SQL_"; SELECT cl_plugins.pid_number as pid, plugin_catalog.pid AS plugin_ +name, plugin_catalog.description AS name, plugin_catalog.version, bui +ld FROM cl_plugins, plugin_catalog WHERE cl_plugins.cid::text = '$proxy->{CID}' AND cl_plugins.pid_number = plugin_catalog.pid_number AND cl_plugins.version::text = plugin_catalog.version::text; _SQL_
In my case, I DO use interpolation, and the string does expand the reference to $proxy->{CID}.

Your query could be:

my $sql=<<"__SQL__"; SELECT to_char(pp.SUBMITTIME, 'YYYY-MM-DD HH:MM:SS') SUBMITTIME, to_char(pp.QUEUETIME, 'YYYY-MM-DD HH:MM:SS') QUEUETIME, to_char(pp.PREPTIME, 'YYYY-MM-DD HH:MM:SS') PREPTIME, to_char(pp.STARTTIME, 'YYYY-MM-DD HH:MM:SS') STARTTIME, pp.SESSIONID, pp.PLANID from '\$hist_plan_prolog_1' pp where pp.SUBMITTIME between '2014-06-26 05:00' and '2014-06-26 08:00:0 +0' order by pp.SUBMITTIME __SQL__
This allows for the potential introduction of perl variables, where you would NOT escape the $.

        What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
              -Larry Wall, 1992

Replies are listed 'Best First'.
Re^2: Escaping and quoting ?????
by AnomalousMonk (Archbishop) on Jul 03, 2014 at 01:07 UTC
    my $sql=<<"__SQL__";

    Use of single-quote delimiters would avoid double-quotish interpolation entirely, with no need for  \ (backslash) escaping:
        my $sql=<<'__SQL__';
    Please see here-docs in Quote and Quote-like Operators.

Re^2: Escaping and quoting ?????
by pgduke65 (Acolyte) on Jul 03, 2014 at 02:42 UTC

    I have updated my original post with the revised code that to use a here document as suggested. But the output seems odd to me? I do not understand why the table names are empty?

      In that case, $hist_plan_prolog_1 does seem to be a variable name. In that case, use NetWallah's second example, but remove the \ before the variable name.

      ~Thomas~ 
      "Excuse me for butting in, but I'm interrupt-driven..."
      "The tool requires that the tables be enclosed in double quotes due to the existence of the $ in the name."
      Try
      "\$hist_nps_1" ns, "\$hist_session_prolog_1" sp, "\$hist_plan_prolog_1" pp, "\$hist_plan_epilog_1" pe
      poj