到底是怎么回事?我创建了一个简单的程序来读取行并在文件上打印输出。但它会引发一些错误......
这是代码,它的解释在评论中:
use warnings;
use List::MoreUtils qw(indexes);
my @array_words = ();
my @array_split = ();
my @array_of_zeros = (0);
my $index = 0;
open my $info, 'models/busquedas.csv';
open my $model, '>>models/model.txt';
#First while is to count the words and store it into an array
while( my $line = <$info>) {
@array_split = regex($line);
for (my $i=0; $i < scalar(@array_split); $i++) {
# Get the index if the word is repeated
$index = indexes { $_ eq $array_split[$i] } $array_words[$i];
# if the word is not repeated then save it to the array by
# checking the index
if ($index != -1){ push(@array_words, $array_split[$i]); }
}
}
print $model @array_words;
sub regex{
# get only basic info like: 'texto judicial madrid' instead of the full url
if ($_[0] =~ m/textolibre=/ and
$. < 3521239 &&
$_[0] =~ m/textolibre=(.*?)&translated/) {
return split(/\+/, $_[0]);
}
}
我不明白的错误是:
Use of uninitialized value $index in numeric ne (!=) at classifier.pl line 21, <$info> line 12216.
Use of uninitialized value $index in numeric ne (!=) at classifier.pl line 21, <$info> line 12216.
Use of uninitialized value $index in numeric ne (!=) at classifier.pl line 21, <$info> line 12216.
Use of uninitialized value $index in numeric ne (!=) at classifier.pl line 21, <$info> line 12217.
Use of uninitialized value $index in numeric ne (!=) at classifier.pl line 21, <$info> line 12217.
Use of uninitialized value $index in numeric ne (!=) at classifier.pl line 21, <$info> line 12217.
Use of uninitialized value $index in numeric ne (!=) at classifier.pl line 21, <$info> line 12217.
Use of uninitialized value $index in numeric ne (!=) at classifier.pl line 21, <$info> line 12217.
Use of uninitialized value $index in numeric ne (!=) at classifier.pl line 21, <$info> line 12218.
Use of uninitialized value $index in numeric ne (!=) at classifier.pl line 21, <$info> line 12218.
为什么未初始化$index
?我已经声明它并用 0 值初始化它!我怎样才能解决这个问题?