該語言是Perl。爲什麼這不在範圍內?爲什麼嚴格使用這個阻止?
#!/usr/bin/perl
use strict;
[...]
while (my $res = $async->wait_for_next_response)
{
[...]
if ($res->is_success)
{
[...]
my @relAuthorList = ($res->content =~ /<a +rel=\"author\" +href=\".*?\".*?>.*?<\/a>/gi);
if (@relAuthorList)
{
if ($#relAuthorlList != 0) # Line 87
{
[...]
}
[...]
}
my @metaAuthorList = ($res->content =~ /<meta +name=\"author\" +content=\".*?\" *?>/gi);
if (@metaAuthorList)
{
if ($#metaAuthorlList != 0) # Line 105
{
[...]
}
[...]
}
[...]
}
[...]
}
當我運行它,我得到這些錯誤:
$ ./findAuthorCanonical
Global symbol "@relAuthorlList" requires explicit package name at ./findAuthorCanonical line 87.
Global symbol "@metaAuthorlList" requires explicit package name at ./findAuthorCanonical line 105.
Execution of ./findAuthorCanonical aborted due to compilation errors.
$
我難倒。嚴格打開。我正在使用my
關鍵字來聲明數組變量。我將=~
運算符的結果作爲列表返回給數組。在我嘗試使用perldata中概述的$#array
獲取最後一個索引之前,我正在測試這些數組以確保它們中有元素。
當我嚴格禁用時,它按預期工作。
我已經試過predeclaring他們作爲陣列之前,我把所有的內容在其中:
my @relAuthorList = [];
my @metaAuthorList = [];
這也不能工作。
圍繞此問題的大部分答案都涉及範圍錯誤,但我無法看到我在此處做出的任何答案。一些涉及忘記與my
宣佈一個變量,但我已經做到了。我看到一個涉及類型不匹配的嘗試將一個標量視爲一個數組。我找不到與此相關的任何內容。
所以我問:我在這裏做錯了什麼?
'[]'創建一個空數組的引用。 '我的@array;'足以初始化一個數組。 –
由於簡單的印刷錯誤,我正在投票關閉這個題目。 –
比較:'@ relAuthorList'與'@ relAuthorlList'和'@ metaAuthorList'與'@ metaAuthorlList'(在「作者」之後的多餘「l」)。 – ThisSuitIsBlackNot