Section 4.9. Here Documents


4.9. 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 inefficientand uglyfor 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"              ;



Perl Best Practices
Perl Best Practices
ISBN: 0596001738
EAN: 2147483647
Year: 2004
Pages: 350
Authors: Damian Conway

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net