| Filter-Indent-HereDoc documentation | view source | Contained in the Filter-Indent-HereDoc distribution. |
Filter::Indent::HereDoc - allows here documents to be indented within code blocks
use Filter::Indent::HereDoc;
{
{
print <<EOT;
Hello, World!
EOT
}
}
# This will print "Hello, World!" and stop at EOT
# even though the termination string is indented.
When a 'here document' is used, the document text and the termination string must be flush with the left margin, even if the rest of the code block is indented.
Filter::Indent::HereDoc removes this restriction, and acts in a more DWIM kind of way - that if the terminator string is indented then that level of indent will apply to the whole document.
If there is no terminator string (so the here document stops at the first blank line), then enough whitespace will be stripped out so that the leftmost character of the document will be flush with the left margin, e.g.
print <<;
Hello,
World!
# This will print:
Hello,
World!
In addition to allowing indented here documents, Filter::Indent::HereDoc also provides support for a more permissive style of terminator string, as specified in Perl6 RFC111. The changes are:
You can force the module to revert to the standard Perl5 style of
terminator string by specifying 'strict_terminators' when the module
is use'd, e.g.
use Filter::Indent::HereDoc; print << EOT Hello, World! EOT ; # this will work use Filter::Indent::HereDoc 'strict_terminators'; print << EOT Hello, World! EOT ; # this will generate an error
no Filter::Indent::HereDoc; to stop the
code from being filtered, e.g.
use Filter::Indent::HereDoc; print <<EOT; This is a here document EOT
no Filter::Indent::HereDoc; print "<<EOT"; # This will be printed as normal
Filter::Simple, http://perl.jonallen.info/modules, perlfaq4, Perl6 RFC111
Jon Allen, <jj@jonallen.info>
Michael Schwern for the suggestions about Perl6 RFC111
Copyright 2003 by Jon Allen
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Filter-Indent-HereDoc documentation | view source | Contained in the Filter-Indent-HereDoc distribution. |