作者:
fju0911 (拉斯維加斯~)
2018-01-11 21:51:08各位前輩大家好。
目前手上在寫一個整理資料的工具時,碰到了底下問題,希望有空的前輩可以解答。
程式碼如下。
問題在於為什麼之後在調用陣列@sort並打印的時候,會出現未初始化的訊息呢?
Use of uninitialized value $sort[0] in concatenation (.) or string at TRY.pl
line 32.
*****
$file = "XXX.txt";
$out= "Sorting_$file";
our @sort;
our @array;
open(FHD,"<$file") || die "Can't open $file!\n";
open(FHO,">$out") || die "Can't open $file!\n";
#Data copy to array#
$n=0;
while ($line=<FHD>) {
$array[$n] = $line;
$n++;
}
close(FHD);
#Data sorting
$F=0;
for($i=0; $i<=$#array; $i++)
{
if ($array[$i]=~ /^</ || $array[$i]=~ /\(F\)/ || $array[$i]=~ /\(A\)/ ||
$array[$i]=~ /{-1}/)
{
$sort[$F] = $array[$i];
# print FHO "$sort[$F]";
}
$F++;
}
print "Array lenth= $#array\n";
print FHO "$array[0]\n";
close(FHO);