[Israel.pm] A question of style - print()

Gaal Yahas gaal at forum2.org
Wed Oct 19 03:14:50 PDT 2005


On Wed, Oct 19, 2005 at 11:54:40AM +0200, Madani, Srikanth, VF-DE wrote:
> After:
> 
> print "\n$0: Warning - couldn't find alias $emails in $EmailAliases",
>         "\nAlias $emails cannot be resolved - no email will be sent.\n",
>         "\nPlease contact file owner to update your desired group in
> $EmailAliases.\n";

You can do even better with a here-document:

print <<"END_WARNING";

$0: Warning - couldn't find alias $emails in $EmailAliases
Alias $emails cannot be resolved - no email will be sent

Please contact file owner to update your desired group in $EmailAliases.
END_WARNING

In Perl 5, this has the wrinkle of requiring the end marker ("END_WARNING"
here) to be flush at the left margin, breaking indentation;
likewise, indentations in the quoted string count as significant
whitespace. Filter::HereDocIndent and Filter::Indent::HereDoc are two
modules that fix this (but are based on source filters).

Perl 6 specifies indentable heredocs in L<S05/Literals/"Here docs allow
optional whitespace">. The syntax for this has been harmonized with
quoting operators in general, as an adverbial modifier. Here's the
example from there:

     print qq:to/END/
         Give $amount to the man behind curtain number $curtain.
         END

(Note that this is a double-quoted, interpolating op. Both p5 and p6
let you use single quotes as well.)

-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/



More information about the Perl mailing list