Domanda

I cant seem to understand the reason for these syntax errors. The following is part of my code. I have strict and warnings implemented.

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;
}

The error I get is:

$ ./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.
È stato utile?

Soluzione

There's syntax error in your code. Change:

if ( defined {season}[0] )

to

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

and

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

to

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

Also you are getting the warning

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

That means you have declared two arrays with the same name @spaa in same scope. You'll probably find Coping with Scoping by Dominus worth reading. Pay particular attention to the section called "Lexical Variables".

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top