On 2008-01-14 13:07:17 +0100, Jenda Krynicky wrote:
> From: "Peter J. Holzer" <[EMAIL PROTECTED]>
> > As an aside, the SPL programming language[2] allows the terminator of a
> > here document to be indented and to strip off everything up to and
> > including some character from each line, so that could be written like
> > this:
> > 
> > function foo() {
> >     some;
> >     code;
> >     here;
> >     if (bla) {
> >         more;
> >         code;
> >         here;
> >         var sql = >>SQL|
> >             |SELECT
> >             |    jo.departure_date  AS  departure
> >             |,   eq.name            AS  equipment
> >             |,   dp.full_city       AS  departure_city
> >             |,   ap.full_city       AS  arrival_city
> >             |,   ca.name            AS  carrier_name
> >             |,   jo.number
> >             |[...]
> >         SQL;
> >         even;
> >         more;
> >     }
> >     code;
> >     here;
> > }
> 
> That kinda defeats the purpose of heredocs, namely allowing me to 
> copy&paste some data into/out of the script without having to escape 
> or modify anything.

In most cases this works with q{} just the same (the only exception is
the sequence \\, which unfortunately represents only a single backslash
inside q{}.

> If you do this and then need to test and tweak the SQL in some UI
> provided by your database you have to go and strip and later
> reintroduce the |s.

Yes, that works for SQL, as I wrote, but not for multi-line strings in
general, where leading whitespace may matter (think of formatted text
output).

Before Clifford introduced that feature into SPL, we discussed several
formats. I think one of them included a "column 0 marker" in the first
line - something like that:

        var sql = >>^SQL|
                    SELECT
                        jo.departure_date  AS  departure
                    ,   eq.name            AS  equipment
                    ,   dp.full_city       AS  departure_city
                    ,   ap.full_city       AS  arrival_city
                    ,   ca.name            AS  carrier_name
                    ,   jo.number
                    [...]
        SQL;

where everything to the left of the marker ("^" here) would be stripped
off. That would simplify cut'n'paste a bit. I don't remember why he
didn't do it that way, but one obvious problem with this approach is
that "to the left of" is ambiguous if tabs and spaces are mixed.

> Not for me, I'd rather have a few lines that are not indented.

As I wrote I prefer just using q{}. As you can see in my example, it has
all lines indented and you can simply cut and paste.

        hp

-- 
   _  | Peter J. Holzer    | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR       | I'd be programming in Java.
| |   | [EMAIL PROTECTED]      | I don't, and I'm not.
__/   | http://www.hjp.at/ |   -- Jesse Erlbaum on dbi-users

Attachment: pgpo6sTwTG4Iw.pgp
Description: PGP signature

Reply via email to