gpt4 book ai didi

perl - 解密此语法错误

转载 作者:行者123 更新时间:2023-12-02 10:54:51 24 4
gpt4 key购买 nike

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

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.

最佳答案

您的代码中存在语法错误。更改:

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值得一读。请特别注意“词汇变量”部分。

关于perl - 解密此语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23667909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com