A string in Perl is a scalar variable and it can contain alphabets, numbers, special characters. The string can consist of a single word, a group of words or a multi-line paragraph. Multi-line string is required in a scenario where the user wants a complete paragraph or a group of paragraphs as a string and for that, he or she needs to preserve the spaces and newline. Multi-line string can be created using various ways.
Multiline String using Single & Double Quotes
User can create a multiline string using the single(”) quotes and as well as with double quotes(“”). Using double quotes cause variables embedded in the string to be replaced by their content while in single quotes variables name remained the same.
This is multiline string using double quotes on GFG This is multiline string using single quotes on $GeeksforGeeks
Multi-line string using Here Document
Here Document is an alternative way for multiple print statements. A Here-Document can also be used for multi-line string. It declares a delimiter at the start to know till where the string needs to take input. A Here-Document starts with ‘<<' followed by the delimiter of the user’s choice. The string reads the code until the delimiter occurs again and all the text in between is taken as the string.
Multiline string using Here-Document on GFG Multiline string using Here-Document on GFG Multiline string using Here-Document on $GeeksforGeeks
Explanation: In the above code if the delimiter put into double quotes then the variables embedded in the string will replace by their content like variable GeeksforGeeks replaced by GFG and this termed as the Interpolating Here Document. If the delimiter put into single quotes then the variables embedded in the string will not replace by their content and this is termed as the Non-interpolating Here Document. Remember if the delimiter is not put into any quotes then by default double quotes are considered around that.
Note: It is recommended to use the same delimiter at the end of the string exactly as it was at the beginning means there should be no white-spaces before, and no white spaces after the delimiter. Otherwise, Perl will not recognize it and will give the error. In other words, the user cannot indent the end tag to match the indentation of the rest of your code.
Can’t find string terminator “string_ending_delimiter” anywhere before EOF at /home/1873b0a5dae105b4bfa82e3c79f156c5.pl line 9.
- Sorting mixed Strings in Perl
- Perl | Quoted, Interpolated and Escaped Strings
- Perl | Basic Syntax of a Perl Program
- Perl vs C/C++
- Perl vs Python
- Recursion in Perl
- Perl vs Java
- Perl | Classes in OOP
- Perl | next operator
- Use of print() and say() in Perl
- Perl | Hashes
- Perl | uc() Function
- Perl | CGI Programming
- Perl | given-when Statement
- Perl | tr Operator
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.