Free Trial

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

Share this Page URL
Help

Values and Expressions > Heredoc Indentation - Pg. 61

remaining lines have to be fully left-justified. That justification can also compromise your code's indentation structure. Here Documents Use a heredoc when a multiline string exceeds two lines. The "break-after-newlines-and-concatenate" approach is fine for a small number of lines, but it starts to become inefficient--and ugly--for larger chunks of text. For multiline strings that exceed two lines, use a heredoc: $usage = <<"END_USAGE"; Usage: $0 <file> [-full] [-o] [-beans] Options: -full : produce a full dump -o : dump in octal -beans : source is Java END_USAGE instead of: $usage = "Usage: $0 <file> [-full] [-o] [-beans]\n" . "Options:\n" . " -full : produce a full dump\n" . " -o : dump in octal\n" . " -beans : source is Java\n" ; Heredoc Indentation Use a "theredoc" when a heredoc would compromise your indentation. Of course, even if your lines are all simple strings, the problem with using a heredoc in the middle of code is that its contents must be left-justified, regardless of the indentation level of the code it's in: if ($usage_error) { warn <<'END_USAGE'; Usage: qdump <file> [-full] [-o] [-beans] Options: -full : produce a full dump -o : dump in octal -beans : source is Java END_USAGE } Heredoc Indentation | This is the Title of the Book, eMatter Edition Copyright © 2009 O'Reilly & Associates, Inc. All rights reserved. 61