Programming Tips - What is the syntax for php and perl heredocs?
Keywords: heredoc, inline text, multiline
Q. What is the syntax for php and perl heredocs?
The syntax is close but different enough to drive me crazy.
my $mydoc = <<<EOT
my $mydoc = <<EOT;
There is no exact equivalent but you can take advantage of a trick:
C/C++ will concatenate adjacent strings.
char *mydoc =
Use sprintf() to put variables into a string.
Again, there is no heredoc. But you can use a backslash for more
compact multiline strings:
var mydoc =
On Android use a string resource.
Regular Java doesn't have an official way but this works OK:
String mydoc =
"line one\n" +
"line two\n" +
Use triple double quotes:
String mydoc = """
I said "hello"