0
我是perl的新手,並且正在嘗試讀取和寫入perl中的csv文件。但是沒有任何事情會發生,有人可以幫我解決問題所在。我可以使用'<'閱讀而不會出現問題,但我無法寫入。正在讀取和寫入文件
use strict;
use warnings;
use Text::CSV_XS;
my $file = 'file.csv';
my $csv = Text::CSV_XS->new();
open (InCSV, '+>>', $file) or die $!;
while (<InCSV>) {
if ($csv->parse($_)) {
my @columns = $csv->fields();
if($columns[1] eq "01") {
my $str = "Selected $columns[6] \n ";
push(@columns,$str);
print InCSV join("," , @columns), "\n";
}
} else {
my $err = $csv->error_input;
print "Failed to parse line: $err";
}
}
close InCSV;
當我使用+ <寫控制檯寫入時卡住了。另一件事是我不想修改所有的行。我只想寫入滿足條件的特定行。所以寫入一個不同的文件或存儲將成爲一個問題。有沒有更好的辦法 ? – mousey 2011-01-11 18:36:44