伊莉討論區

標題: 關於perl can’t use string as an array ref [打印本頁]

作者: 幻想的夢境    時間: 2022-7-16 01:07 PM     標題: 關於perl can’t use string as an array ref

as title
我有一個檔案是這樣的
file:
@fruit: apple banana
@area: area1 area2 area3

我的程式這樣寫

use strict;
my @fruit;
my @area;

open fid,”<file”;
while(<fid>){
  if($_ =~ /^\s*(\S*?)\s*:\s*(.*)$/){
    @$1=split('\s+',$2);
    next;
  }
}

已經先以perl -c確認過語法沒問題
但在執行時,顯示
can't use string as an array ref while strict refs in use
我是不是哪邊沒注意到?
因為這個用法我以前有用過,確定能用
我有嘗試拿掉strict,array一樣是empty
所以來請教一下各路高手,這該怎麼寫才正確
先謝謝




歡迎光臨 伊莉討論區 (http://www06.eyny.com/) Powered by Discuz!