2014-05-15 91 views
0

我似乎無法理解這些語法錯誤的原因。以下是我的代碼的一部分。我有嚴格的警告和警告。解密此語法錯誤

my $res = $s->scrape(URI->new($urlToScrape)); 

#warn Dump $res; 
print "Show :".$res->{showtitle}[0]; 
my @sct; 
if (defined {season}[0]) { 
    print $res->{season}[0]; 
    @sct=split(' ', $res->{season}[0]); 
} else { 
    my @spaa=split({showtitle}[0], {fulltitle}[0]); 
    print "Couldnt find season num at proper position\n"; 
    print $spaa[0]."\n"; 
    print $spaa[1]."\n"; 
    exit; 
} 

我得到的錯誤是:

$ ./htmlscrape.pl 
"my" variable @spaa masks earlier declaration in same scope at ./htmlscrape.pl line 43. 
"my" variable @spaa masks earlier declaration in same scope at ./htmlscrape.pl line 44. 
syntax error at ./htmlscrape.pl line 37, near "}[" 
syntax error at ./htmlscrape.pl line 40, near "}" 
syntax error at ./htmlscrape.pl line 46, near "}" 
Execution of ./htmlscrape.pl aborted due to compilation errors. 
+0

您需要發佈更多的代碼才能確定,但​​語法錯誤非常明顯:您已在其他位置聲明瞭「@ spaa」。 –

+0

不應該定義$ res - > {season} [0]''定義{season} [0]'嗎? –

+0

'{showtitle} [0],{fulltitle} [0]' – TLP

回答

1

有沒有在你的代碼的語法錯誤。變化:

if (defined {season}[0]) 

if (defined $res->{season}[0]) 

my @spaa=split({showtitle}[0], {fulltitle}[0]); 

my @spaa=split($res->{showtitle}[0], $res->{fulltitle}[0]); 

而且你所得到的警告

"my" variable @spaa masks earlier declaration in same scope at ./htmlscrape.pl line 43.

這意味着你已經在同一範圍內聲明瞭兩個同名的數組@spaa。你可能會發現Dominus的Coping with Scoping值得一讀。請特別注意「詞彙變量」部分。

+0

'@ spaa'錯誤是語法錯誤的結果,由於某種原因它會觸發兩次。 – TLP