Put your html in a single string. This way you know if you match things you should not match, like so:
#!/usr/bin/perl
use Mojo::DOM;
my $dom = Mojo::DOM->new();
$|=1;
$text='
<a class="ab">2016-05-18</a>
<a class="a b">2016-05-19</a>
<a class="b">2016-05-20</a>
<a class="a">2016-05-21</a>
';
my $test1=$dom->parse($text)->at('a.ab')->text;
print "18: $test1\n";
my @test2=$dom->parse($text)->find('a.a b')->map('text')->each;
print "19: @test2 (bad)\n";
my $test3=$dom->parse($text)->at('a.a.b')->text;
print "19: $test3\n";
18: 2016-05-18
19: 2016-05-18 2016-05-19 2016-05-20 2016-05-21 (bad)
19: 2016-05-19
Note, the find('a.a b') does not match anything, so to make it more interesting, I did a find('a. a b')
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.