[請益] 迴圈內變數複製

看板Perl作者 (拉斯維加斯~)時間7年前 (2018/01/11 13:51), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
各位前輩大家好。 目前手上在寫一個整理資料的工具時,碰到了底下問題,希望有空的前輩可以解答。 程式碼如下。 問題在於為什麼之後在調用陣列@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); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.162.25 ※ 文章網址: https://www.ptt.cc/bbs/Perl/M.1515678670.A.9BF.html
文章代碼(AID): #1QLslEc_ (Perl)
討論串 (同標題文章)
以下文章回應了本文
1
1
完整討論串 (本文為第 1 之 2 篇):
7年前, 2018/01/11 13:51
1
1
文章代碼(AID): #1QLslEc_ (Perl)