Can't call method “setValue” on an undefined value - perl

use strict;
use warnings;
use utf8;
use 5.010;
use HTML::HTML5::Parser;

open (FILE, '<links.txt') ;

my @lines = <FILE>;
my $i;
my $a = $lines[$i];

my $xml = HTML::HTML5::Parser->load_html(location => $a) ;

got error: "Can't call method "setValue" on an undefined value at C:/Dwimperl/perl/site/lib/ HTML/HTML5/Parser/TagSoupParser.pm line 2946"

I've tried to insert an if and define value first but it doesn't work.

I'm at the beginning of learning Perl, could anyone here help me with this?

Answers


use strict;
use warnings;
use utf8;
use 5.010;
use HTML::HTML5::Parser;
use Try::Tiny;

open (my $FILE, '<', 'links.txt') ;
my @lines = <$FILE>;
my $i = 0;
foreach my $a (@lines) {
    my $xml = try {
        HTML::HTML5::Parser->load_html(location => $a)
    } catch {
        warn "Bad line [$i][$a]";
        warn "Actual error: $_";
    };
    $i++;
}

I've cleaned up your code with my best guess as to how it's actually supposed to be structured, and added a try/catch block (using Try::Tiny) to demonstrate a method of identifying your problem lines.

You need to identify what input is causing the problem before you can really diagnose the problem.


Need Your Help

Extending log4j Logger

java log4j

I have application which heavily use log4j out of the box. This uses lots of third party APIs. Some of these third party API completely hacks our logger and wipes out our appenders sometimes comple...

PHP encoding to only have letters and numbers

php

Is there a encoding function in PHP which will encode strings and the resulting output will only contain letters and numbers? I would use base64 but that still has some stuff which is not

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.