Perl 中的“Here”文件
你可以非常方便地儲存或列印多行文字。甚至可以在“here”文件內使用變數。下面是一個簡單的語法,仔細檢查,<<和識別符號之間一定不能有空格。
識別符號既可以是裸詞,也可以是引號包圍的文字,如下面的 EOF。如果識別符號帶有引號,則使用的引號型別將決定文件中的文字處理方式,就像在常規引號中一樣。未加引號的識別符號的作用類似於雙引號。
示例
#!/usr/bin/perl $a = 10; $var = <<"EOF"; This is the syntax for here document and it will continue until it encounters a EOF in the first line. This is case of double quote so variable value will be interpolated. For example value of a = $a EOF print "$var\n"; $var = <<'EOF'; This is case of single quote so variable value will be interpolated. For example value of a = $a EOF print "$var\n";
輸出
將產生以下結果 −
This is the syntax for here document and it will continue until it encounters a EOF in the first line. This is case of double quote so variable value will be interpolated. For example value of a = 10 This is case of single quote so variable value will be interpolated. For example value of a = $a
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP