作者jacky1989 ()
看板Perl
标题[问题] can't use string as an array ref
时间Fri Jul 15 21:11:36 2022
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
所以来请教一下各路高手,这该怎麽写才正确
先谢谢了
--
Sent from my iPhone 7
○ PiTT
// PHJCI
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 49.216.20.62 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Perl/M.1657890698.A.EF2.html
1F:→ lgen7604: 问题是@$ 用hash应该可解 $hash{$1}=split('\s+',$2); 07/19 09:09