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
In reply to Mojo::DOM exception handling help by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |