I'm reading an article about Quixote at the moment, and I came across this Python code, which looks rather ugly to me:
template _q_index (request): """ ... """ bug_db = get_bug_database() for bug in bug_db.get_all_bugs(): ... """ ... """I've never been a fan of triple-quoted strings. I prefer HEREDOCs, even when they require that extra end token.
Then I started thinking: do HEREDOCs need an end token?:
#!/usr/bin/perl -w print <<""; This is a test. This is only a test. print "\t(you have been warned.)\n";Apparently not. :-)
Can't find string terminator "" anywhere before EOF...
Re:Really?
ziggy on 2004-08-27T16:53:58
What version of Perl? Are you sure there's a blank line between the end of the HEREDOC and the print statement?I've just tested it with 5.005_03, 5.6.1 and 5.8.0. The script works fine in all three.
Re:Really?
phillup on 2004-08-27T17:38:46
program:But... I found the problem.print <<"";
This is a test.
This is only a test.
print "\t(you have been warned.)\n";
There are two spaces on the blank line due to my editor's "auto indent" feature. (and my stupidity)
I'm using Quanta, which is part of KDE... and I just upgraded it this last weekend and haven't gotten all the kinks worked out in it's configuration.
Sorry for the false alarm.
---
So, should this also work?I suspect tht the HEREDOC (in your example) is really just extending to the end of the file and you got lucky by choosing a print statement. Since you are using double quotes it is getting interpolated and everything works out.#!/usr/bin/perl -w
print <<"";
This is a test.
This is only a test.
my $test = 'what about non-print statements';
print "\t(you have been warned.)\n";
print "$test\n";Re:Really?
ziggy on 2004-08-27T17:54:16
Um, no. Luck has nothing to do with it.I suspect tht the HEREDOC (in your example) is really just extending to the end of the file and you got lucky by choosing a print statement. Since you are using double quotes it is getting interpolated and everything works out.I don't have an editor that is ever-so-helpfully putting spaces on blank lines when I don't want them there. The HEREDOC ends at the first blank line. Period. There is nothing magical about the second print statement.
Re:Really?
phillup on 2004-08-27T18:19:14
I don't have an editor that is ever-so-helpfully putting spaces on blank lines when I don't want them there. The HEREDOC ends at the first blank line. Period. There is nothing magical about the second print statement.
Dammit! (I did it again... didn't I)
;-)
Confirmed... thanks.
Re:Great minds think alike.
Aristotle on 2004-08-27T22:19:31
Vim has no problem doing the right thing with autoindent: if you hit [Enter] multiple times, despite Vim placing the cursor at the correct indent on each line, the empty lines will be left completely blank. Only once you enter text or navigate away will the cursor location manifest itself as whitespace.
I've never once had an autoindent-related whitespace surprise.