[英]perl file handler not writing to file
下面的文件處理程序FILE無法正常工作,我是否缺少明顯的東西? 我無法將其寫入文件$ failed_launches嗎?
open(my $data, '<', $file) or die "Could not open '$file' $!\n";
while (my $line = <$data>) {
chomp $line;
if ($csv->parse($line)) {
my @fields = $csv->fields();
foreach ($fields[1] =~ /Problems/ || $fields[1] =~ /Failure/) {
open (FILE, ">>", "$failed_launches") or die "can't open $failed_launches $!";
while ($line = <FILE>){
print "$line\n";
}
close (FILE);
$status = 1;
$msg = "CMR:'$fields[0]' unsuccessful, contact SE team";
SendStatus($fields[2], $status, $msg);
}
foreach ($fields[1] =~ /Success/){
$status = 0;
$msg = "CMR:'$fields[0]' was successful!";
SendStatus($fields[2], $status, $msg);
}
} else {
warn "Line could not be parsed: $line\n";
}
在這里打開FILE
進行寫入:
open (FILE, ">>", "$failed_launches") or die "can't open $failed_launches $!";
但是在這里您嘗試從FILE
讀取; 您從未真正寫任何東西!
while ($line = <FILE>){
您正在打開FILE
進行寫入,但沒有寫入。 相反,您正在從中閱讀。 如果要通過print
語句寫入FILE
。 就是這樣
print FILE "text";
我想你也想做的就是將$line
寫入FILE
。 你應該這樣
open (FILE, ">>", "$failed_launches") or die "can't open $failed_launches $!";
print FILE "$line\n";
close (FILE);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.