[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.7 A Here String

A ‘here string’ is formed in much the same way as a shell here doc. It is denoted with two less than characters(<<) and, optionally, a hyphen. This is followed by optional horizontal white space and an ending marker-identifier. This marker must follow the syntax rules for identifiers. Unlike the shell version, however, you must not quote this marker.

The resulting string will start with the first character on the next line and continue up to but not including the newline that precedes the line that begins with the marker token. The characters are copied directly into the result string. Mostly.

If a hyphen follows the less than characters, then leading tabs will be stripped and the terminating marker will be recognized even if preceded by tabs. Also, if the first character on the line (after removing tabs) is a backslash and the next character is a tab or space, then the backslash will be removed as well. No other kind of processing is done on this string.

Here are three examples:

 
str1 = <<-  STR_END
        $quotes = " ' `
        STR_END;

str2 = <<   STR_END
        $quotes = " ' `
        STR_END;
STR_END;

str3 = <<-  STR_END
        \	$quotes = " ' `
        STR_END;

The first string contains no new line characters. The first character is the dollar sign, the last the back quote.

The second string contains one new line character. The first character is the tab character preceding the dollar sign. The last character is the semicolon after the STR_END. That STR_END does not end the string because it is not at the beginning of the line. In the preceding case, the leading tab was stripped.

The third string is almost identical to the first, except that the first character is a tab. That is, it exactly matches the first line of the second string.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Bruce Korb on August 21, 2015 using texi2html 1.82.