in reply to Re: (jeffa) 3: SQL Query
in thread SQL Query

No they don't. BIND VARS neatly takes care of quoting issues:
my $sth = $dbh->prepare(' insert into foo(bar,baz) values (?,?) '); $sth->execute($foo,$bar);

Here docs would clutter this. Syntax highlighters should treat here docs and strings the same, my gvim highlighter does ...

NOT! (update) Sorry, the gvim syntax highlighter tends to treat the characters inside a here document as perl code, while strings are one color except for interpolated variables and escaped characters. But anyhow...

Save yourself the carpel tunnel. ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

<update>

Thanks gmax! I have 'posted' the instructions at my perlmonks site: http://jeffa.perlmonk.org/vi/highlight_embed.html.

</update>

Replies are listed 'Best First'.
Re: (jeffa) 5Re: SQL Query
by gmax (Abbot) on Jan 11, 2002 at 12:36 UTC
    Just a quick addition. Here documents have their pro and cons, and I take your point. However, one of the reasons for having a here doc is that you can set a different syntax highlighting. In Vim (or gvim) you can edit the perl.vim syntax file and impose a different set of colors for your SQL code. The only hairy thing is that you need to define a unique separator.
    In my case, I have defined two areas where I want this particular double syntax, inside a qq{} string (without spaces before the brace. If I want normal perl syntax, I use qq {}) and inside here documents starting with <<SQL. This way I can decide which one to use, whether or not I am using hash variables inside my SQL string. I use bind vars inside my SQL, and they don't interfere with my double syntax highlighting.

    The stylistic issue can be seen differently here, if we consider that we can have a separate syntax highlighting for embedded SQL (or HTML, XML, or whatever thing we are building from our Perl script).
    More than style, I would say it is convenience, since syntax highlighting will catch typing mistakes before I close my editor. Since I produce and maintain several Perl/DBI scripts, I found a balance between how much to write and how much help I want to get from my editor. Besides, if I catch the error earlier, it's one time less that I have to fire the editor and modify the code.
    OTOH, this benefit is lost when I send my code to somebody who doesn't benefit from this feature.
    I just wanted to share my experience. A mix of personal taste and style.
    _ _ _ _ (_|| | |(_|>< _|
Re: (jeffa) 6: SQL Query
by dmmiller2k (Chaplain) on Jan 11, 2002 at 08:49 UTC

    Ah! No wonder. Say no more. I just checked your Perl Geek Code.

    Ee-- indeed :)

    dmm