我有一个文件
#File content
word1 -> word2
word3 -> word4
我需要把它放在2个不同的数组中
@array1 = word1, word3
@array2 = word2, word4
我的代码如下
my @mappings = `cat $file_name`;
foreach my $map (@mappings) {
$map =~ s/^\s+|\s+$//g; #Remove leading and trailing spaces
next if ($map =~ /^#/);
my @Mainarray = split ('->',$map);
my @array1 = push(@array1,@Mainarray[0]); **#Error line**
my @array2 = push(@array2,@Mainarray[1]); **#Error line**
print("Array1: @array1\nArray2:@array2\n");
}
我收到此错误:
Global symbol "@array1" requires explicit package name.
Global symbol "@array2" requires explicit package name.
有人可以帮我解决这个问题。