Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

4. Values and Expressions > Multiline Strings

Multiline Strings

Lay out multiline strings over multiple lines.

If a string has embedded newline characters, but the entire string won’t fit on a single source line, then break the string after each newline and concatenate the pieces:

$usage = "Usage: $0 <file> [-full]\n"
         . "(Use -full option for full dump)\n"         ;

In other words, the internal appearance of the string should mirror its external (printed) appearance as closely as possible.

Don’t, however, be tempted to make the newline implicit, by wrapping a single string across multiple lines, like so:

$usage = "Usage: $0 <file> [-full]
(Use -full option for full dump)
";

Even though actual line breaks inside such a string do become newline characters within the string, the readability of such code suffers severely. It’s harder to verify the line structure of the resulting string, because the first line is indented whilst the remaining lines have to be fully left-justified. That justification can also compromise your code’s indentation structure.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint