Skip to content

Allow indented SQL heredoc marker#216

Open
NickHibma wants to merge 1 commit into
vim-perl:masterfrom
NickHibma:patch-1
Open

Allow indented SQL heredoc marker#216
NickHibma wants to merge 1 commit into
vim-perl:masterfrom
NickHibma:patch-1

Conversation

@NickHibma
Copy link
Copy Markdown

In properly indented code it is nicer to be able to do

    my $a = << "    SQL"
        SELECT something FROM somewhere
    SQL

avoiding the need to put the second 'SQL' without whitespace prefix, but this requires the inclusion of the white space in the here document terminator.

In properly indented code it is nicer to be able to do

  my $a = << "  SQL"
    SELECT something FROM somewhere
  SQL

avoiding the need to put the second 'SQL' without whitespace prefix, but this requires the inclusion of the white space in the here document terminator.
@petdance
Copy link
Copy Markdown
Contributor

@NickHibma: Thanks for the pull request.

Is your documentation example correct? Shouldn't the end of the heredoc be indented?

I'm kind of itchy about this idea. Something seems weird about this idea, but I'm not sure I can put my finger on it.

@NickHibma
Copy link
Copy Markdown
Author

I've fixed the example. And yes, there is something wrong with adding the whitespace in the terminator. But having your indenting screwed up doesn't cut it either. I usually use quoting operators instead because of it.

In shell scripts you can use cat <<-EOF (note the '-') to remove any extra indenting, but that is not available in Perl (5).

@gedge
Copy link
Copy Markdown

gedge commented Apr 10, 2019

worth revisiting a recent perldoc perlop and seeing <<~EOF for indented here-docs in perl (yes, the EOF line can be indented)

@hoelzro
Copy link
Copy Markdown
Member

hoelzro commented Apr 11, 2019

@gedge I believe that form of indentation is already handled by vim-perl

@hoelzro
Copy link
Copy Markdown
Member

hoelzro commented Apr 11, 2019

Er, sorry - I realized once I hit "Comment" that you may have been suggesting this to the PR author as an alternative to whitespace-prefixing their heredoc delimiter!

@cees
Copy link
Copy Markdown

cees commented Apr 12, 2019

If code cleanliness is the goal with indented SQL statements, it is possible to use an empty heredoc marker which means the indenting problem goes away:

    my $a = << ""
        SELECT something FROM somewhere

    my $sth = $dbh->prepare($a);

I suspect you always have an empty newline after every SQL statement anyway, so it is quite natural to format the code this way. An empty end of line marker may scare some people, but I thought i would throw it out as an alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants