Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello wise Monks who are always wiser than I am. I have several thousand html files that I'm parsing using Mojo::DOM. I've encountered a few older files that are surprisingly missing one the fields I'm trying to extract. Not many by enough to cause my script to error out. Here's the code I have:
my $dom1 = Mojo::DOM->new( $$temp_content ); my $abstr = $dom1->at('div.abstract-content > p')->text; print "Abstract is: $abstr \n\n";
Here's the what I tried to do to catch the exception (when abstract is null)
my $abstr = $dom1->at('div.abstract-content > p' || 'not provided')- +>text;
Here's the error that I'm getting: Can't call method "text" on an undefined value at /Volumes/HD-PATU3/test.pl line 5.
I've looked at the Mojo::DOM documentation and can't seem to find an answer. I've sure it's easy and being a nub I"m missing something simple. Thanks in advance for your wisdom and assistance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mojo::DOM exception handling help
by davido (Cardinal) on Aug 01, 2020 at 19:35 UTC | |
|
Re: Mojo::DOM exception handling help
by kcott (Archbishop) on Aug 01, 2020 at 22:59 UTC | |
|
Re: Mojo::DOM exception handling help
by stevieb (Canon) on Aug 01, 2020 at 17:20 UTC | |
by haukex (Archbishop) on Aug 01, 2020 at 19:15 UTC | |
|
Re: Mojo::DOM exception handling help
by Anonymous Monk on Aug 01, 2020 at 18:51 UTC |