解密此语法错误

时间:2014-05-15 01:41:01

标签: perl compiler-errors syntax-error

我似乎无法理解这些语法错误的原因。以下是我的代码的一部分。我已经实施了严格的警告。

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.

1 个答案:

答案 0 :(得分: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值得一读。请特别注意名为"词汇变量"。

的部分
相关问题