Randal Schwartz has a great article here HERE .
There are a few things to remember about documents:
; in Perl, it is an operator terminator and is required for all Perl statements (with some exceptions), including document lines here;- This document is a fun view that really is just a big line;
- This document should have a trailing CR (unlike most other Perl statements);
- You can have arbitrary Perl code either immediately after the opening tag, or after the closing tag. If after the closing tag it should be on a separate line. In any case, the code works on the text of the line here:
- The quotation marks you use in tags affect the string. Double quotes are similar to double quote strings in Perl, single quotes do not interpolate, back quotes are passed to the shell. Quotation marks are not equivalent to double quotation marks;
- TIMTOWTDI, but some are hard to read,
Quote from perldoc -q "HERE documents" (and perlfaq4 ):
There should be no space after the <part.
There (maybe) there should be a semicolon at the end of the [part << ].
You cannot (easily) have a place in front of a tag.
The two forms that you have are functionally equivalent. Just like { ... } if (blah blah) matches if (blah blah) { ... } . Although the two statements are functionally equivalent, they read differently.
Each of these is equivalent and valid for Perl documents:
my %data = <<END fred: Fred Flintstone barney: Barney Rubble betty: Betty Rubble wilma: Wilma Flintstone END =~ /(\w+): (.*)/g;
and
my %data = <<END =~ /(\w+): (.*)/g; fred: Fred Flintstone barney: Barney Rubble betty: Betty Rubble wilma: Wilma Flintstone END
Both set the %data hash to first=>"full name" for Flintstones. Which would you rather see in the code that came to you?
Note that the second form is the one where gotcha is: There must be text or a space after the ending label, or you can get Can't find string terminator "END" anywhere before EOF I think thatโs why you see lonely ; for some people here are docs,
IMHO,; belongs after the first instance of the doc here tag or the code that follows it. It is harder to read if it is after the closing tag. If the closing tag is not in a form similar to an operator modifier or warning or matrix logic. This is just my personal leadership style.
dawg
source share