我在CSV文件中有數據(IP地址),它將成爲9-13列。如果其他列中沒有值,那麼在默認情況下,它應該只打印第9列中的內容。有一個輸出文件將打印一組值和第9列的值(如果值爲13存在)與一個靜態值連接以創建一個別名值。我的問題是,你如何有效地做到這一點?我有這樣的代碼工作:如何編寫Perl腳本來檢查x列以在每行返回值的另一行中輸出值
my $alias0= "ComponentAliases=['ComputerSystem:$columns[9]'];\n";
my $alias1= "ComponentAliases=['ComputerSystem:$columns[9]','ComputerSystem:$columns[10]'];\n";
my $alias2= "ComponentAliases=['ComputerSystem:$columns[9]','ComputerSystem:$columns[10]','ComputerSystem:$columns[11]'];\n";
print BAROC "ComputerSystem;\n";
if(($columns[11] != '')&&($columns[10] != '')) { print BAROC $alias2 }
elsif(($columns[11] == '')&&($columns[10] != '')) { print BAROC $alias1 }
elsif(($columns[11] == '')&&($columns[10] == '')) { print BAROC $alias0 }
這個工程做我想做的事情,但有一個機會,CSV文件將在列9-13或9-11值,等我輕鬆認爲靜態寫這篇文章會很好,但我希望有效地做到這一點,並理解並始終應用最佳實踐。我不熟悉Perl腳本,但不斷吸取它來解決工作中的問題。建議?
這是輸出,順便說一句:
ComponentAliases=['ComputerSystem:10.1.0.225','ComputerSystem:10.200.252.77','ComputerSystem:10.100.252.77'];