2016-02-26 37 views
-2

我有以下Perl代碼:爲什麼我在EOF之前的任何地方出現錯誤「無法找到字符串終止符」END_HTML?

  use strict; 
      use warnings; 
      use MIME::Lite; 
      use HTML::Entities; 
      use Time::localtime; 
      use Sys::Hostname; 

      my $ti = localtime; 
      my ($day,$month,$year)=($ti->mday,$ti->fullmonth,$ti->year); 
      my $HOSTNAME =hostname(); 

      my $greeting = <<END_HTML;  
      <p style="width:600px;margin:0 100px"><font face="Arial" size="3"><strong>$month $day, $year</strong></font></p><br> 
      <p style="width:600px;margin:0 100px"><font face="Arial" size="3" color="#3a7df9"><strong>Status of Update on '$HOSTNAME' machine</strong></font></p><br> 
      END_HTML 
      my $html = '<table style="width:600px;margin:0 100px" border="1" BORDERCOLOR="#000000"> 
      <thead><th bgcolor="#9fc0fb">Successful Update</th><th bgcolor="#9fc0fb">Failed Update</th></thead> 
      <tbody>'; 

它工作正常,在Eclipse中,但是當我嘗試從Windows批處理文件運行它,它失敗,出現錯誤:

Can't find string terminator "END_HTML" anywhere before EOF

我怎樣才能解決這個問題?

+3

你的整個腳本是否真的縮進了?您的here-doc的字符串末尾標識符不能縮進。 – ThisSuitIsBlackNot

+0

刪除縮進清除了問題。謝謝! – Jill448

回答

2

perlop記錄,應該不是之前或之後END_HTML是任何空間:

The terminating string must appear by itself (unquoted and with no surrounding whitespace) on the terminating line.

清理出壓痕刪除錯誤。

相關問題