The here documentation mechanism for Perl is derived from the here document mechanism in the UNIX shell.
As in the shell, the here document in Perl is also a row-oriented reference form, requiring a << operator followed by an initial terminating string.
After <<, no spaces can appear.
If the terminating string is not enclosed in quotation marks or double quotation marks, the variable expression is allowed.
If a single quotation mark is added to the terminating string, the variable expression is not executed. The user should insert the first line of text between the first and last terminating strings.
The last terminating string must be on the line, and white space characters are not allowed around.
Unlike the Unix shell, Perl does not allow command substitution in the here document.
On the other hand, if the terminating string is enclosed in anti-quotes, Perl also allows the command to be executed in the here document.
#!/bin/perl $price = 100;
1 Print <<EOF; # No quotes around Terminator EOF is same # as double quotes
2 The price of $price are right. # Variables is expanded
3 EOF
4 print << ' FINIS ';
5 The price of $price are right. # The variable is not expanded # if Terminator are enclosed in a single quotes
6 FINIS
7 print << x 4; # Prints the Line 4 times
8 Christmas is coming! # Blank line was necessary here as terminating string
9 Print << ' END '; # If Terminator is in Backquotes, # would execute UNIX commands
Ten echo Hi there
Echo-n "The Time is"
Date
END
(Output)
2 The price of are right.
5 The price of $price are right.
8 Christmas is coming!
Christmas is coming!
Christmas is coming!
Christmas is coming!
Ten Hi there the time is Fri 3 17:03:46 PST 2000
"Editor: Clouds TEL: (010) 68476606"
Back to Bibliography previous Section Next One |
Here documentation for Perl learning