next up previous contents index
Next: Arrays Up: Scalar Variables Previous: Single Quoting   Contents   Index

HERE syntax

At times, you may want to assign or print out some lengthy message that would go over multiple lines. This is possible with a simple assignment of a variable as was done above (with possible use of \n to indicate explicit newline breaks), but a more readable alternative may be to use a HERE document. An example of this is as follows:
print << 'END_OF_WARNING';
This is a big
warning message, indicating
something terrible
has gone wrong.
This will print out everything until the closing END_OF_WARNING, which must appear on a line by itself and have no whitespace either before or after it. If you have variables appearing in the string that you want expanded, use double quotes:
$message = << "END_OF_MESSAGE";
This is to inform you, $person, that your account
is overdue by an amount of $over_run. Please pay
by the first day of $month, or we will have to take
drastic action.
Note that newlines are printed as they appear.