Beautiful Perl feature: "heredocs", multi-line strings embedded in source code
Beautiful Perl series This post is part of the beautiful Perl features series. See the introduction post for general explanations about the series. Previous posts covered random topics ranging from...

Source: DEV Community
Beautiful Perl series This post is part of the beautiful Perl features series. See the introduction post for general explanations about the series. Previous posts covered random topics ranging from fundamental concepts like blocks or list context and scalar context to sharp details like reusable subregexes. Today's topic is neither very fundamental nor very sharp: it is just a handy convenience for managing multi-line strings in source code, namely the heredoc feature. This is not essential, because multi-line strings can be expressed by other means; but it addresses a need that is quite common in programming, so it is interesting to compare it with other programming languages. "Heredocs": multi-line data embedded in source code A "here document", abbreviated as "heredoc", is a piece of multi-line text embedded in the source code. Perl borrowed the idea from Unix shells, and was later imitated by other languages like PHP or Ruby (discussed below). So instead of concatenating single lin