Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Mojo::DOM exception handling help

by stevieb (Canon)
on Aug 01, 2020 at 17:20 UTC ( [id://11120201]=note: print w/replies, xml ) Need Help??


in reply to Mojo::DOM exception handling help

This is only an educated guess here, as I don't have the facilities currently to test, nor the time to read docs to understand what's happening. Can you extract the object, check for defined, then act appropriately?

Instead of:

my $abstr = $dom1->at('div.abstract-content > p' || 'not provided')->t +ext;

Will something like this example work?:

my $obj = $dom1->at('div.abstract-content > p' || 'not provided'); my $abstr = defined $obj ? $obj->text : 'Object undefined';

If it does work, you could elaborate on it a little, to say log the entries that are broken.

Replies are listed 'Best First'.
Re^2: Mojo::DOM exception handling help
by haukex (Archbishop) on Aug 01, 2020 at 19:15 UTC

    To the OP: Without having the time to test myself at the moment, what stevieb suggested should work; you can also choose a different action to take with a more complex statement like if ( defined $obj ) { ... } else { ... }. Note that 'div.abstract-content > p' || 'not provided' is actually not doing anything useful, as it's just a logical or and the first value is always true, so the second value will always be ignored.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11120201]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-24 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found