我懷疑的問題是,你的程序不以新行字符"\n"
終止該行。毫無疑問,當你手動編輯文件時,你會將其中一個放入文件中?
像這樣的東西可能會解決它,但我沒有一個Linux盒子,所以我無法測試它。
use strict;
use warnings;
my $pathfile = 'path/to/file';
open my $w_var, '>>', $pathfile or die $!;
print $w_var "Hello\nWorld!\n";
close $w_var;
my $email_command = "mail -s header some\@emailaddress.com < $pathfile";
system $email_command;
編輯
但它會很遠更好使用類似Mail::Sendmail。 Email::Sender是迄今爲止最好的,但與它的依賴關係一起,它是一個非常簡單的任務的巨大模塊,我毫不猶豫地在這裏推薦它。
使用Mail::Sendmail
看起來像這樣的代碼:
use strict;
use warnings;
use Mail::Sendmail;
my $pathfile = 'path/to/file';
open my $w_var, '>>', $pathfile or die $!;
print $w_var "Hello\n", "World!\n";
my $message = do {
open $w_var, '<', $pathfile or die $!;
local $/;
<$w_var>;
};
sendmail(
To => '[email protected]',
From => '[email protected]',
Message => $message,
)
or die $Mail::Sendmail::error;
請包括你實際使用的代碼的相關部分。 – Joni 2012-04-17 11:31:42
嘗試'打開(W_VAR,「>>」,「$ pathfile」)|| printf(「無法打開%s \ n」,$ filepath);' - 看看你是否得到一個錯誤 – scibuff 2012-04-17 11:33:41
好像你錯過了第一行的結束單引號 – JoelFan 2012-04-17 11:42:19